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
import time | |
import analogio | |
import board | |
light = analogio.AnalogIn(board.LIGHT) | |
while True: | |
print((light.value,)) | |
time.sleep(0.1) |
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
CSV | |
==== | |
import csv | |
with open('swapi.csv') as f: | |
reader = csv.reader(f) | |
items = list(reader) | |
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
""" | |
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. |
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
# 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, |
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
import time | |
print('start') | |
for i in range(10): | |
print(i) | |
time.sleep(1) | |
print('stop') |
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 * | |
radio.on() | |
while True: | |
if radio.receive(): | |
display.show(image.DUCK) | |
if accelerometer.was_gesture('shake'): | |
radio.send('duck') | |
sleep(20) |
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
# Add your Python code here. E.g. | |
import speech | |
line1 = [ | |
'#26DEYYYYYYYYY', | |
'#31ZIYIYIYIYIYIYIY', | |
'#39DEYYYYYYYYY', | |
'#52ZIYIYIYIYIYIYIY', | |
'#46GIXV', | |
'#42MIYIY', |
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
import nativeio | |
import time | |
from board import SPEAKER | |
notes = { | |
'b': 26, | |
'a#': 27, | |
'a': 28, | |
'g#': 29, |
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
""" | |
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(): | |
""" |
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 | |
radio.on() | |
while True: | |
msg = radio.receive_bytes() | |
if msg: | |
uart.write(msg[3:]) |