欢迎来到 黑吧安全网 聚焦网络安全前沿资讯,精华内容,交流技术心得!

TPYBoard之DIY一个无线装甲小车

来源:本站整理 作者:佚名 时间:2018-07-26 TAG: 我要投稿
 
 M4_0=pyb.Timer(2, freq=10000).channel(3, pyb.Timer.PWM, pin=pyb.Pin.board.Y9, pulse_width=0)
 M4_1=pyb.Timer(12, freq=10000).channel(2, pyb.Timer.PWM, pin=pyb.Pin.board.Y8, pulse_width=(speed*100)+10000)
 
 led_red.value(1)
 
def stop():
 M1_0=pyb.Timer(8, freq=10000).channel(1, pyb.Timer.PWM, pin=pyb.Pin.board.Y1, pulse_width=0)
 M1_1=pyb.Timer(8, freq=10000).channel(2, pyb.Timer.PWM, pin=pyb.Pin.board.Y2, pulse_width=0)
 
 M2_0=pyb.Timer(4, freq=10000).channel(3, pyb.Timer.PWM, pin=pyb.Pin.board.Y3, pulse_width=0)
 M2_1=pyb.Timer(4, freq=10000).channel(4, pyb.Timer.PWM, pin=pyb.Pin.board.Y4, pulse_width=0)
 
 M3_0=pyb.Timer(1, freq=10000).channel(1, pyb.Timer.PWM, pin=pyb.Pin.board.Y6, pulse_width=0)
 M3_1=pyb.Timer(1, freq=10000).channel(2, pyb.Timer.PWM, pin=pyb.Pin.board.Y7, pulse_width=0)
 
 M4_0=pyb.Timer(12, freq=10000).channel(2, pyb.Timer.PWM, pin=pyb.Pin.board.Y8, pulse_width=0)
 M4_1=pyb.Timer(2,  freq=10000).channel(3, pyb.Timer.PWM, pin=pyb.Pin.board.Y9, pulse_width=0)
 led_right.value(0)
 led_left.value(0)
 led_red.value(1)
 
def left(speed):
 M1_0=pyb.Timer(8, freq=10000).channel(1, pyb.Timer.PWM, pin=pyb.Pin.board.Y1, pulse_width=(speed*30)+10000)
 M1_1=pyb.Timer(8, freq=10000).channel(2, pyb.Timer.PWM, pin=pyb.Pin.board.Y2, pulse_width=0)
 
 M2_0=pyb.Timer(4, freq=10000).channel(3, pyb.Timer.PWM, pin=pyb.Pin.board.Y3, pulse_width=(speed*100)+10000)
 M2_1=pyb.Timer(4, freq=10000).channel(4, pyb.Timer.PWM, pin=pyb.Pin.board.Y4, pulse_width=0)
 
 M3_0=pyb.Timer(1, freq=10000).channel(1, pyb.Timer.PWM, pin=pyb.Pin.board.Y6, pulse_width=(speed*30)+10000)
 M3_1=pyb.Timer(1, freq=10000).channel(2, pyb.Timer.PWM, pin=pyb.Pin.board.Y7, pulse_width=0)
 
 M4_0=pyb.Timer(2, freq=10000).channel(3, pyb.Timer.PWM, pin=pyb.Pin.board.Y9, pulse_width=(speed*100)+10000)
 M4_1=pyb.Timer(12, freq=10000).channel(2, pyb.Timer.PWM, pin=pyb.Pin.board.Y8, pulse_width=0)
 led_right.value(1)
 led_left.value(0)
 
def right(speed):
 M1_0=pyb.Timer(8, freq=10000).channel(1, pyb.Timer.PWM, pin=pyb.Pin.board.Y1, pulse_width=(speed*200)+20000)
 M1_1=pyb.Timer(8, freq=10000).channel(2, pyb.Timer.PWM, pin=pyb.Pin.board.Y2, pulse_width=0)
 
 M2_0=pyb.Timer(4, freq=10000).channel(3, pyb.Timer.PWM, pin=pyb.Pin.board.Y3, pulse_width=(speed*200)+3000)
 M2_1=pyb.Timer(4, freq=10000).channel(4, pyb.Timer.PWM, pin=pyb.Pin.board.Y4, pulse_width=0)
 
 M3_0=pyb.Timer(1, freq=10000).channel(1, pyb.Timer.PWM, pin=pyb.Pin.board.Y6, pulse_width=(speed*100)+20000)
 M3_1=pyb.Timer(1, freq=10000).channel(2, pyb.Timer.PWM, pin=pyb.Pin.board.Y7, pulse_width=0)
 
 M4_0=pyb.Timer(2, freq=10000).channel(3, pyb.Timer.PWM, pin=pyb.Pin.board.Y9, pulse_width=(speed*100)+3000)
 M4_1=pyb.Timer(12, freq=10000).channel(2, pyb.Timer.PWM, pin=pyb.Pin.board.Y8, pulse_width=0)
 led_right.value(0)
 led_left.value(1)
 
while True:
    if blue.any()>0:
        data=blue.read().decode()
        print(data)
        if data.find('0')>-1:
            stop()
        if data.find('1')>-1:
            pyb.LED(2).on()
            pyb.LED(3).off()
            pyb.LED(4).off()
            go(5)
        if data.find('2')>-1:
            pyb.LED(2).off()
            pyb.LED(3).on()
            pyb.LED(4).off()
            back(5)
        if data.find('3')>-1:
            pyb.LED(2).off()
            pyb.LED(3).off()
            pyb.LED(4).on()
            left(5)
        if data.find('4')>-1:
            pyb.LED(2).off()
            pyb.LED(3).off()
            pyb.LED(4).on()
            right(5)
需要自己组装小车,硬件接线不需要接,只需要将单片机和蓝牙模块插到扩展板上,然后把程序复制到main.py中,然后手机下载好app,就可以控制小车爬坡,前进,后退了,动手造起来吧!!!!
 

上一页  [1] [2] 

【声明】:黑吧安全网(http://www.myhack58.com)登载此文出于传递更多信息之目的,并不代表本站赞同其观点和对其真实性负责,仅适于网络安全技术爱好者学习研究使用,学习中请遵循国家相关法律法规。如有问题请联系我们,联系邮箱admin@myhack58.com,我们会在最短的时间内进行处理。
  • 最新更新
    • 相关阅读
      • 本类热门
        • 最近下载