Last active
January 11, 2018 00:46
-
-
Save lbxa/702eb1be2145fa7fb3c76d71f1e016d1 to your computer and use it in GitHub Desktop.
NCSS remote control driver
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 * | |
import music | |
import random | |
DEF_CHANNEL = 22 | |
RADIO_PROTOCOL = "robot:" | |
# left: 0, 16 | |
# right: 12, 8 | |
def forward(speed=100): | |
pin0.write_analog(0) | |
pin16.write_analog(speed) | |
pin12.write_analog(speed) | |
pin8.write_analog(0) | |
def back(speed=100): | |
pin0.write_analog(speed) | |
pin16.write_analog(0) | |
pin12.write_analog(0) | |
pin8.write_analog(speed) | |
def right(speed, thresh): | |
pin0.write_analog(0) | |
pin16.write_analog(speed) | |
pin12.write_analog(speed - (speed / thresh)) | |
pin8.write_analog(0) | |
def left(speed, thresh): | |
pin0.write_analog(0) | |
pin16.write_analog(speed - (speed / thresh)) | |
pin12.write_analog(speed) | |
pin8.write_analog(0) | |
radio.config(channel=DEF_CHANNEL) | |
radio.on() | |
while True: | |
display.show(Image.ANGRY) | |
remote_msg = radio.receive() | |
if remote_msg: | |
if remote_msg.startswith(RADIO_PROTOCOL): | |
if remote_msg == RADIO_PROTOCOL + "left": | |
forward(1000) | |
sleep(5000) | |
left(1000, 1) | |
sleep(5000) | |
elif remote_msg == RADIO_PROTOCOL + "right": | |
forward(1000) | |
sleep(5000) | |
right(1000, 1) | |
sleep(5000) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment