-
-
Save ukBaz/eef3d420e5e04330649f637b1df63425 to your computer and use it in GitHub Desktop.
Simple line following code for 4tronix bitbot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add your Python code here. E.g. | |
from microbit import * | |
import neopixel | |
np = neopixel.NeoPixel(pin13, 12) | |
speed = 250 | |
reduce_by = 4 | |
red = (40, 0, 0) | |
green = (0, 40, 0) | |
def leds(left, right): | |
for x in range(0, 5): | |
np[x] = left | |
for x in range(6, 11): | |
np[x] = right | |
np.show() | |
def left_motor(pwm_value, rev=0): | |
pin0.write_analog(pwm_value) | |
pin8.write_digital(0) | |
def right_motor(pwm_value, rev=0): | |
pin1.write_analog(pwm_value) | |
pin12.write_digital(0) | |
def spin_left(fast_speed): | |
slow_speed = 0 | |
left_motor(slow_speed) | |
right_motor(fast_speed) | |
def spin_right(fast_speed): | |
slow_speed = 0 | |
left_motor(fast_speed) | |
right_motor(slow_speed) | |
def forward(fast_speed): | |
left_motor(fast_speed) | |
right_motor(fast_speed) | |
while True: | |
lline = pin11.read_digital() | |
rline = pin5.read_digital() | |
if (lline == 1): | |
display.show(Image.ARROW_W) | |
leds(red, green) | |
spin_left(speed) | |
elif (rline == 1): | |
display.show(Image.ARROW_E) | |
leds(green, red) | |
spin_right(speed) | |
else: | |
display.show(Image.ARROW_N) | |
leds(green, green) | |
forward(speed) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment