Last active
September 24, 2016 10:34
-
-
Save jake-walker/0b46b479f589b3978442b74d7b86d6ab to your computer and use it in GitHub Desktop.
A simple BBC Micro:bit script that allows you to send radio messages to another Micro:bit that is running this same script
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 microbit import * | |
import radio | |
# --- CONFIG --- | |
# Deadzone | |
deadzone = 350 | |
# Scroll Speed (ms) | |
scrollspeed = 500 | |
current = 1 | |
characters = [" ", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", " "] | |
message = [] | |
space = Image("00000:" | |
"00000:" | |
"00000:" | |
"90009:" | |
"99999") | |
newMessage = Image("05950:" | |
"50505:" | |
"95059:" | |
"99599:" | |
"99999") | |
tick = Image("00000:" | |
"00009:" | |
"00090:" | |
"90900:" | |
"09000") | |
radio.on() | |
def drawChar(): | |
if characters[current] == " ": | |
display.show(space) | |
else: | |
display.show(characters[current]) | |
def appendCurrent(): | |
if button_a.is_pressed(): | |
message.append(characters[current]) | |
print(''.join(message)) | |
display.show(Image().invert()) | |
sleep(scrollspeed) | |
elif button_b.is_pressed(): | |
radio.send(''.join(message)) | |
message = [] | |
current = 1 | |
display.show(tick) | |
sleep((scrollspeed * 2)) | |
def checkForMessages(): | |
incoming = radio.receive() | |
if incoming: | |
display.show(newMessage) | |
sleep(250) | |
display.clear() | |
sleep(250) | |
display.show(newMessage) | |
sleep(250) | |
display.clear() | |
sleep(250) | |
display.show(newMessage) | |
sleep(250) | |
display.clear() | |
sleep(250) | |
display.show(newMessage) | |
sleep(250) | |
display.clear() | |
sleep(250) | |
display.scroll(incoming) | |
while True: | |
reading = accelerometer.get_x() | |
checkForMessages() | |
if reading > deadzone: | |
if current < (len(characters) - 1): | |
current = current + 1 | |
drawChar() | |
appendCurrent() | |
sleep(scrollspeed) | |
elif reading < (deadzone * -1): | |
if current > 0: | |
current = current - 1 | |
drawChar() | |
appendCurrent() | |
sleep(scrollspeed) | |
else: | |
drawChar() | |
appendCurrent() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment