Skip to content

Instantly share code, notes, and snippets.

@ukBaz
Created December 29, 2016 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ukBaz/eef3d420e5e04330649f637b1df63425 to your computer and use it in GitHub Desktop.
Save ukBaz/eef3d420e5e04330649f637b1df63425 to your computer and use it in GitHub Desktop.
Simple line following code for 4tronix bitbot
# 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