我正在使用 Micro:Bit 和 Bit:Bot 做一些简单的事情,但从 Bit:Bot 电机得到了意想不到的结果。
简而言之,我正在尝试:
- 将 Bit:Bot 向前移动 1 秒(打开几个绿色 Neopixels)
- 停止电机(并清除所有新像素)
- 反向(打开一些红色 Neopixels)
这是我用 MicroPython 编写的程序:
from microbit import *
import neopixel
# pin13 gives access to the robot's neopixels.
myLightShow = neopixel.NeoPixel(pin13,12)
myLightShow[3]= (0,255,0)
myLightShow[4]= (0,225,0)
myLightShow[5]= (0,255,0)
myLightShow[9]= (0,255,0)
myLightShow[10]= (0,255,0)
myLightShow[11]= (0,255,0)
myLightShow.show()
#for driving the motors the following pins are used:
#pin8 (left wheel) and pin12 (right wheel) sets the direction.
#set pin to 0 for forward, set pin to 1 for reverse
# pin0 (left wheel) and pin1 (right wheel) sets speed. 0 - 1023 range
# both, therefore, are write_analog statements.
#Below, the 5 statements tell motors to go forward, at speed 300 for 1 sec
pin8.write_digital(0)
pin12.write_digital(0)
pin0.write_analog(300)
pin1.write_analog(300)
sleep(1000)
#Stop motors and clear neopixels (i.e. off)
pin0.write_analog(0)
pin1.write_analog(0)
pin8.write_digital(0)
pin12.write_digital(0)
myLightShow.clear()
# reverse at speed 350
pin8.write_digital(1)
pin12.write_digital(1)
pin0.write_analog(350)
pin1.write_analog(350)
# turn on selected neopixels and show.
myLightShow[0]= (255,0,0)
myLightShow[1]= (255,0,0)
myLightShow[2]= (255,0,0)
myLightShow[6]= (255,0,0)
myLightShow[7]= (255,0,0)
myLightShow[8]= (255,0,0)
myLightShow.show()
当我在我的 bit:bot 上运行程序时,它按预期向前移动 1 秒,然后停止(如预期),但随后又继续向前移动!
我多年来一直在解决这个问题,但不知道问题是什么。
有人可以帮忙吗?谢谢