Example 1 bluebit重力遥控小车

来自Labplus盛思维基百科
Senadmin讨论 | 贡献2018年1月30日 (二) 10:50的版本
跳转至: 导航搜索

Part list:

  • 1x micro:bit
  • 1x blue:bit-主板
  • 2x blue:bit-电机驱动


Description:
通过micro:bit重力感应遥控blue:bit小车
使用方法:按下micro:bit A按键左右前后倾斜,通过2轴重力控制小车

Connection:

小车左电机 AN1->P14
AN2->P13
小车右电机 AN1->P16
AN2->P15
重力小车.png



Programs:

  • microbit重力遥控端程序
from microbit import *
import radio
radio.on()
radio.config(length=8, queue=3, channel=79, power=7, 
             address=0x44773311, group=0x1B, data_rate=radio.RATE_250KBIT)
    
msg = bytearray(5)
x = 0
y = 0
z = 0
a = 0
while True:
    x = accelerometer.get_x()
    y = accelerometer.get_y()
    z = accelerometer.get_z()
    if button_a.is_pressed():
        a=1 
    else:
        a=0
    
    x = x + 10000;
    msg[0] = int(x / 256)
    msg[1] = x % 256
    y = y + 10000;
    msg[2] = int(y / 256)
    msg[3] = y % 256
    msg[4] = a
    radio.send_bytes(msg)
    sleep(50)