Created
October 26, 2017 15:08
-
-
Save VlastimilHovan/df599b943bda4a36fffbe7f64f6ae7ff to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from microbit import * | |
pin8.set_analog_period(1) | |
pin12.set_analog_period(1) | |
pin0.set_analog_period(1) | |
pin16.set_analog_period(1) | |
def_speed = 512 | |
def move_forward(): | |
pin8.write_analog(def_speed) | |
pin12.write_analog(0) | |
pin0.write_analog(def_speed) | |
pin16.write_analog(0) | |
motor_direction = 1 #movement identifier | |
return | |
def move_backward(): | |
pin8.write_digital(0) #motor left side | |
pin12.write_digital(1) | |
pin0.write_digital(0) #motor right side | |
pin16.write_digital(1) | |
motor_direction = 2 #movement identifier | |
return | |
def move_right(): | |
pin8.write_analog(def_speed) | |
pin12.write_analog(0) | |
pin0.write_analog(def_speed) | |
pin16.write_analog(def_speed) | |
motor_direction = 3 #movement identifier | |
return | |
def move_left(): | |
pin8.write_analog(def_speed) | |
pin12.write_analog(def_speed) | |
pin0.write_analog(def_speed) | |
pin16.write_analog(0) | |
motor_direction = 4 #movement identifier | |
return | |
def move_break(): | |
pin8.write_analog(def_speed) | |
pin12.write_analog(def_speed) | |
pin0.write_analog(def_speed) | |
pin16.write_analog(def_speed) | |
motor_direction = 5 #movement identifier | |
return | |
def move_coast(): | |
pin8.write_digital(0) #motor left side | |
pin12.write_digital(0) | |
pin0.write_digital(0) #motor right side | |
pin16.write_digital(0) | |
motor_direction = 6 #movement identifier | |
return | |
motor_direction = 0 | |
while True: | |
if (motor_direction != 1): | |
if ((button_a.is_pressed() == True) & (button_b.is_pressed() == True)): | |
move_forward() | |
display.clear() | |
display.show(Image.ARROW_N) | |
if (motor_direction != 5): | |
if ((button_a.is_pressed() == False) & (button_b.is_pressed() == False)): | |
move_break() | |
display.clear() | |
display.scroll("Sensor error - robot STOP !!!", delay=100) | |
if (motor_direction != 4): | |
if ((button_a.is_pressed() == False) & (button_b.is_pressed() == True)): | |
move_left() | |
display.clear() | |
display.show(Image.ARROW_NW) | |
if (motor_direction != 3): | |
if ((button_b.is_pressed() == False) & (button_a.is_pressed() == True)): | |
move_right() | |
display.clear() | |
display.show(Image.ARROW_NE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment