-
-
Save ukBaz/a2b805f49a58a7ab49a817731d4bcf01 to your computer and use it in GitHub Desktop.
Remote control for 4Tronix Bit:Bot
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
from guizero import * | |
from bluezero import microbit | |
print('scanning...') | |
bitbot = microbit.BitBot('micro:bit') | |
def connect(): | |
print('connecting') | |
bitbot.connect() | |
print('connected!') | |
def disconnect(): | |
bitbot.disconnect() | |
def do_nothing(): | |
return 0 | |
def stop(): | |
bitbot.drive(0, 0) | |
def forward(): | |
bitbot.drive(100, 100) | |
def reverse(): | |
bitbot.drive(-90, -90) | |
def forward_left(): | |
bitbot.drive(75, 100) | |
def forward_right(): | |
bitbot.drive(100, 75) | |
def left(): | |
bitbot.drive(0, 75) | |
def right(): | |
bitbot.drive(75, 0) | |
def reverse_left(): | |
bitbot.drive(-75, -100) | |
def reverse_right(): | |
bitbot.drive(-100, -75) | |
def _build_direction(box_obj): | |
button1 = PushButton(box_obj, forward_left, text=u'\u2196', grid=[0, 0]) | |
button2 = PushButton(box_obj, forward, text=u'\u2191', grid=[0, 1]) | |
button3 = PushButton(box_obj, forward_right, text=u'\u2197', grid=[0, 2]) | |
button4 = PushButton(box_obj, left, text=u'\u2190', grid=[1, 0]) | |
button5 = PushButton(box_obj, stop, text=u'\u25A0', grid=[1, 1]) | |
button6 = PushButton(box_obj, right, text=u'\u2192', grid=[1, 2]) | |
button7 = PushButton(box_obj, reverse_left, text=u'\u2199', grid=[2, 0]) | |
button8 = PushButton(box_obj, reverse, text=u'\u2193', grid=[2, 1]) | |
button9 = PushButton(box_obj, reverse_right, text=u'\u2198', grid=[2, 2]) | |
def _build_connect_btns(box_obj): | |
con_btn = PushButton(box_obj, connect, text='Connect', grid=[0, 0]) | |
dis_btn = PushButton(box_obj, disconnect, text='Disconnect', grid=[0, 1]) | |
def _build_horn_section(box_obj): | |
buzz_on = PushButton(box_obj, bitbot.buzzer_on, text='on', grid=[0, 0]) | |
buzz_off = PushButton(box_obj, bitbot.buzzer_off, text='off', grid=[0, 1]) | |
if __name__ == '__main__': | |
app = App(title='BitBot Control', | |
height=300, | |
width=200, | |
layout='grid') | |
# Title | |
text = Text(app, 'BitBot control', grid=[0,0]) | |
# pic = Picture(app, 'bitbot.jpg', grid=[0, 0]) | |
con_btns = Box(app, layout='grid', grid=[1, 0]) | |
buzz_title = Text(app, 'Direction Control', grid=[2, 0]) | |
dir_btns = Box(app, layout='grid', grid=[3, 0]) | |
buzz_title = Text(app, 'Horn Control', grid=[4, 0]) | |
buz_btns = Box(app, layout='grid', grid=[5, 0]) | |
_build_connect_btns(con_btns) | |
_build_direction(dir_btns) | |
_build_horn_section(buz_btns) | |
app.display() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment