Added simple radio test
authorNeil Smith <neil.git@njae.me.uk>
Wed, 26 Oct 2016 14:49:44 +0000 (15:49 +0100)
committerNeil Smith <neil.git@njae.me.uk>
Wed, 26 Oct 2016 14:49:44 +0000 (15:49 +0100)
.gitignore [new file with mode: 0644]
radio_test/radio_receive.py [new file with mode: 0644]
radio_test/radio_send.py [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..f6cc5da
--- /dev/null
@@ -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 (file)
index 0000000..33d62f5
--- /dev/null
@@ -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 (file)
index 0000000..557e80c
--- /dev/null
@@ -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