I’m using a Micro:Bit and Bit:Bot to do some simple things but am getting unexpected results from the Bit:Bot motor.
Simply put, i’m trying to:
- move the Bit:Bot forward for 1 second (with a few Green Neopixels on)
- Stop motors (& clear all neopixels)
- reverse (with some Red Neopixels on)
Here is my program, written in 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()
When i run the program on my bit:bot, it moves forward for 1 second, as expected, then stops (as expected) but then continues to move forward again!
I have been troubleshooting this for ages and don’t know what the problem is.
Can anyone help please? Thanks