From: Neil Smith Date: Wed, 26 Oct 2016 14:49:44 +0000 (+0100) Subject: Added simple radio test X-Git-Url: https://git.njae.me.uk/?a=commitdiff_plain;h=a9046aad297cbf504227e165a5593e927eac8f0e;p=microbit.git Added simple radio test --- a9046aad297cbf504227e165a5593e927eac8f0e diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f6cc5da --- /dev/null +++ b/.gitignore @@ -0,0 +1,55 @@ +*.py[cod] + +# C extensions +*.so + +# Packages +*.egg +*.egg-info +dist +build +eggs +parts +bin +var +sdist +develop-eggs +.installed.cfg +lib +lib64 +__pycache__ + +# Installer logs +pip-log.txt + +# Unit test / coverage reports +.coverage +.tox +nosetests.xml + +# Translations +*.mo + +# Mr Developer +.mr.developer.cfg +.project +.pydevproject + +# IPython +.ipynb* + +# Sublime text +*.sublime-workspace + +# Logs +*.log + +# Databases +*sqlite3 + +# Virtual environment +djangogirls + +# Django static files +/static +.DS_Store diff --git a/radio_test/radio_receive.py b/radio_test/radio_receive.py new file mode 100644 index 0000000..33d62f5 --- /dev/null +++ b/radio_test/radio_receive.py @@ -0,0 +1,33 @@ +from microbit import * +import radio + +A_IMAGE = Image('00009:' + '09990:' + '90090:' + '90090:' + '09999') + +B_IMAGE = Image('90009:' + '90000:' + '99900:' + '90090:' + '99900') + +radio.on() + +display.scroll('Ready', wait=False, loop=True) +last_receive_time = None +display_image = None + +while True: + message = radio.receive() + if message: + last_receive_time = running_time() + if message == 'a': + display_image = A_IMAGE + if message == 'b': + display_image = B_IMAGE + elif last_receive_time: + dimness = (running_time() - last_receive_time) / 500 + if dimness > 9: dimness = 9 + display.show(display_image / dimness , wait=False) diff --git a/radio_test/radio_send.py b/radio_test/radio_send.py new file mode 100644 index 0000000..557e80c --- /dev/null +++ b/radio_test/radio_send.py @@ -0,0 +1,36 @@ +from microbit import * +import radio + +A_IMAGE = Image('09909:' + '90090:' + '99990:' + '90090:' + '90090') + +B_IMAGE = Image('99909:' + '90090:' + '99900:' + '90090:' + '99900') + +display.scroll('Press', wait=False, loop=True) +last_sent_time = None + +while True: + if button_a.was_pressed(): + display_image = A_IMAGE + last_sent_time = running_time() + radio.on() + radio.send('a') + radio.off() + if button_b.was_pressed(): + display_image = B_IMAGE + last_sent_time = running_time() + radio.on() + radio.send('b') + radio.off() + if last_sent_time: + dimness = (running_time() - last_sent_time) / 500 + if dimness > 9: dimness = 9 + display.show(display_image / dimness, wait=False) + \ No newline at end of file