Skip to content

Instantly share code, notes, and snippets.

View ntoll's full-sized avatar
🎵
This statement is false...

Nicholas Tollervey ntoll

🎵
This statement is false...
View GitHub Profile
from micropython import *
import random
dots = [ [0]*5, [0]*5, [0]*5, [0]*5, [0]*5 ]
while True:
dots[random.randrange(5)][random.randrange(5)] = 9
for i in range(5):
for j in range(5):
display.set_pixel(i, j, dots[i][j])
dots[i][j] = max(dots[i][j] - 1, 0)
@ntoll
ntoll / conductor.py
Created October 2, 2016 16:09
The conductor script for starting the other two micro:bits.
import radio
from microbit import button_a, display, Image
radio.on()
display.show(Image.HAPPY)
while True:
if button_a.was_pressed():
radio.send('go')
@ntoll
ntoll / ode1.py
Created October 2, 2016 16:10
Top line of Beethoven's Ode to Joy. Requires another micro:bit running conductor.py to start it.
import speech
import radio
from microbit import display, Image
phrases = [
"#31froyderr " # Freude
"#29sherr#26ner " # schoner
"gerr#29terr#31fuhnx#35kahn" # Gotterfunken
"#39taaaakterr " # Tochter
@ntoll
ntoll / ode2.py
Created October 2, 2016 16:11
Harmony line for Beethoven's Ode to Joy. Requires a micro:bit running conductor.py to start.
import speech
import radio
from microbit import display, Image
phrases = [
"#39froyderr " # Freude
"#35sherr#31ner " # schoner
"gerr#35terr#39fuhnx#52kahn" # Gotterfunken
"#62taaaakterr " # Tochter
@ntoll
ntoll / rps.py
Created January 30, 2017 15:39
Rock, paper, scissors
from microbit import accelerometer, display, Image, sleep
import random
pictures = [
Image('55555:55555:55555:55555:55555'), # Rock
Image('50005:05050:00500:55055:55055'), # Scissors
Image('55500:50050:50005:50005:55555'), # Paper
]
while True:
from microbit import *
import radio
radio.on()
while True:
msg = radio.receive_bytes()
if msg:
uart.write(msg[3:])
"""
Listen to a connected micro:bit for incoming messages to which you can react
as needs apply.
"""
from serial.tools.list_ports import comports as list_serial_ports
from serial import Serial
def find_microbit():
"""
@ntoll
ntoll / jacques.py
Created March 13, 2017 15:27
Circuit Playground Music in Python
import nativeio
import time
from board import SPEAKER
notes = {
'b': 26,
'a#': 27,
'a': 28,
'g#': 29,
@ntoll
ntoll / daisy.py
Created April 11, 2017 12:49
MicroPython code for singing "Daisy, Daisy" on a micro:Bit
# Add your Python code here. E.g.
import speech
line1 = [
'#26DEYYYYYYYYY',
'#31ZIYIYIYIYIYIYIY',
'#39DEYYYYYYYYY',
'#52ZIYIYIYIYIYIYIY',
'#46GIXV',
'#42MIYIY',
from microbit import *
radio.on()
while True:
if radio.receive():
display.show(image.DUCK)
if accelerometer.was_gesture('shake'):
radio.send('duck')
sleep(20)