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
@ntoll
ntoll / light_sensor.py
Created June 25, 2018 11:14
Code for reading the light-sensor readings from a Circuit Playground Express board by Adafruit.
import time
import analogio
import board
light = analogio.AnalogIn(board.LIGHT)
while True:
print((light.value,))
time.sleep(0.1)
CSV
====
import csv
with open('swapi.csv') as f:
reader = csv.reader(f)
items = list(reader)
@ntoll
ntoll / main.py
Created April 10, 2018 09:57
Attack of the Killer-Cave Plotter from the Planet Raxxla!
"""
Attack of the Killer-Cave Plotter from the Planet Raxxla!
by Nicholas H.Tollervey. Released into the public domain.
Instructions:
Open Mu, put it into Adafruit mode and switch on the REPL
and plotter.
@ntoll
ntoll / crapamagotchi.py
Created August 8, 2017 14:38
A really crap Tamagotchi for micro:bit
# Make the display sparkle. Click button A to show an image for
# a moment before the sparkles start again. Click button B to
# scroll a friendly message before the sparkles return.
# By Nicholas H.Tollervey and released to the Public Domain.
# How would you improve this code?
from microbit import *
import random
# A full list of images can be found here: http://bit.ly/1WY221q
images = [Image.HAPPY, Image.SAD, Image.GHOST, Image.SKULL,
import time
print('start')
for i in range(10):
print(i)
time.sleep(1)
print('stop')
from microbit import *
radio.on()
while True:
if radio.receive():
display.show(image.DUCK)
if accelerometer.was_gesture('shake'):
radio.send('duck')
sleep(20)
@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',
@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,
"""
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():
"""
from microbit import *
import radio
radio.on()
while True:
msg = radio.receive_bytes()
if msg:
uart.write(msg[3:])