Permalink
Browse files

Initial commit.

  • Loading branch information...
ntoll committed Sep 13, 2017
0 parents commit 806a29e90cb999a3c7ccc37a5b08f6d12b2a87a7
Showing with 1,628 additions and 0 deletions.
  1. +7 −0 02-PyBoard/blink.py
  2. +8 −0 03-BBC_microbit/blink.py
  3. +10 −0 04-Adafruit_Circuit_Playground/blink.py
  4. +11 −0 05-ESP8266-32/blink.py
  5. +20 −0 07-Visual_Feedback/circuit_playground_neopixels_alive.py
  6. +13 −0 07-Visual_Feedback/circuit_playground_pwm_brightness.py
  7. +11 −0 07-Visual_Feedback/microbit_custom_brightness_image.py
  8. +5 −0 07-Visual_Feedback/microbit_happy.py
  9. +5 −0 07-Visual_Feedback/microbit_hello_world.py
  10. +6 −0 07-Visual_Feedback/microbit_image_from_bytearray.py
  11. +12 −0 07-Visual_Feedback/microbit_wopr.py
  12. +6 −0 07-Visual_Feedback/pyboard_lcd_hello_world.py
  13. +58 −0 07-Visual_Feedback/pyboard_lcd_modrian.py
  14. +16 −0 07-Visual_Feedback/pyboard_lcd_snow_crash.py
  15. +12 −0 07-Visual_Feedback/pyboard_pwm_brightness.py
  16. +67 −0 08-Input_and_Sensing/circuit_playground_audio_record.py
  17. +29 −0 08-Input_and_Sensing/circuit_playground_buttons.py
  18. +20 −0 08-Input_and_Sensing/circuit_playground_switch.py
  19. +35 −0 08-Input_and_Sensing/circuit_playground_touch.py
  20. +9 −0 08-Input_and_Sensing/esp8266_button.py
  21. +27 −0 08-Input_and_Sensing/microbit_accelerometer_tail.py
  22. +10 −0 08-Input_and_Sensing/microbit_compass.py
  23. +15 −0 08-Input_and_Sensing/microbit_event_loop.py
  24. +11 −0 08-Input_and_Sensing/microbit_gestures.py
  25. +7 −0 08-Input_and_Sensing/microbit_touch.py
  26. +10 −0 08-Input_and_Sensing/pyboard_switch_callback.py
  27. +9 −0 08-Input_and_Sensing/pyboard_switch_loop.py
  28. +11 −0 08-Input_and_Sensing/pyboard_touch_paint.py
  29. +9 −0 09-GPIO/esp8266_interrupt.py
  30. +7 −0 09-GPIO/microbit_uart.py
  31. +115 −0 10-Networking/circuit_playground_ir_receive.py
  32. +66 −0 10-Networking/circuit_playground_ir_send.py
  33. +25 −0 10-Networking/esp8266_mqtt_publish.py
  34. +24 −0 10-Networking/esp8266_mqtt_subscribe.py
  35. +11 −0 10-Networking/esp8266_star_wars.py
  36. +33 −0 10-Networking/esp8266_web_server.py
  37. +26 −0 10-Networking/microbit_firefly.py
  38. +12 −0 10-Networking/microbit_listener.py
  39. +60 −0 10-Networking/microbit_mesh_bathroom.py
  40. +60 −0 10-Networking/microbit_mesh_kitchen.py
  41. +60 −0 10-Networking/microbit_mesh_lounge.py
  42. +15 −0 10-Networking/microbit_radio_hello.py
  43. +43 −0 10-Networking/pc_listener.py
  44. +19 −0 11-Sound_and_Music/circuit_playground_first_bloop.py
  45. +49 −0 11-Sound_and_Music/circuit_playground_frere_jacques.py
  46. +42 −0 11-Sound_and_Music/circuit_playground_metronome.py
  47. +15 −0 11-Sound_and_Music/circuit_playground_play_wav.py
  48. +52 −0 11-Sound_and_Music/circuit_playground_wave_forms.py
  49. +49 −0 11-Sound_and_Music/microbit_beat_box.py
  50. +65 −0 11-Sound_and_Music/microbit_daisy_bell.py
  51. +4 −0 11-Sound_and_Music/microbit_nyan.py
  52. +15 −0 11-Sound_and_Music/microbit_pentatonic_instrument.py
  53. +4 −0 11-Sound_and_Music/microbit_say_hello.py
  54. +15 −0 11-Sound_and_Music/microbit_sing.py
  55. +6 −0 11-Sound_and_Music/microbit_strangled_cat_o_phone.py
  56. +22 −0 11-Sound_and_Music/music.py
  57. +16 −0 11-Sound_and_Music/pyboard_generative_music.py
  58. +12 −0 11-Sound_and_Music/pyboard_whitenoise.py
  59. BIN 11-Sound_and_Music/sound.wav
  60. +63 −0 12-Robots/microbit_racer_controller.py
  61. +71 −0 12-Robots/microbit_racer_driver.py
  62. +62 −0 12-Robots/microbit_trundle_bot.py
  63. +21 −0 README.rst
@@ -0,0 +1,7 @@
# Taken from the REPL based example.
import pyb
while True:
pyb.LED(1).toggle()
pyb.delay(500)
@@ -0,0 +1,8 @@
from microbit import display, sleep
while True:
display.set_pixel(2, 2, 9)
sleep(500)
display.set_pixel(2, 2, 0)
sleep(500)
@@ -0,0 +1,10 @@
# Taken from the REPL based example.
from board import D13
import digitalio
import time
led = digitalio.DigitalInOut(D13)
led.switch_to_output()
while True:
led.value = not led.value
time.sleep(0.5)
@@ -0,0 +1,11 @@
# Taken from the REPL based example.
from machine import Pin
import time
led = Pin(2, Pin.OUT)
while True:
led.value(not led.value())
time.sleep(0.5)
@@ -0,0 +1,20 @@
import neopixel
import random
import time
from board import NEOPIXEL
np = neopixel.NeoPixel(NEOPIXEL, 10, auto_write=False)
step = 32
while True:
for i in range(10):
for j in range(10):
np[j] = tuple((max(0, val - step) for val in np[j]))
r = random.randint(0, 255)
g = random.randint(0, 255)
b = random.randint(0, 255)
np[i] = (r, g, b)
np.write()
time.sleep(0.05)
@@ -0,0 +1,13 @@
# Taken from the REPL based example.
from board import D13
import time
import pulseio
pin = pulseio.PWMOut(D13)
while True:
for i in range(16):
pin.duty_cycle = 2 ** i
time.sleep(0.1)
@@ -0,0 +1,11 @@
from microbit import display, Image
my_picture = Image(
'33333:'
'36663:'
'36963:'
'36663:'
'33333:')
display.show(my_picture)
@@ -0,0 +1,5 @@
# Taken from the REPL based example.
from microbit import display, Image
display.show(Image.HAPPY)
@@ -0,0 +1,5 @@
# Taken from the REPL based example
from microbit import display
display.scroll("Hello World!", delay=80, wait=False, loop=True, monospace=True)
@@ -0,0 +1,6 @@
from microbit import display, Image
buf = bytearray(x % 10 for x in range(100))
i = Image(10, 10, buf)
display.show(i.crop(3, 4, 5, 5))
@@ -0,0 +1,12 @@
from microbit import *
import random
import array
def animation():
blinkenlights = array.array('b', [random.randint(0, 9) for i in range(25)])
yield Image(5, 5, blinkenlights)
while True:
display.show(animation())
@@ -0,0 +1,6 @@
import lcd160cr
lcd = lcd160cr.LCD160CR('X')
lcd.erase()
lcd.write('Hello, World!')
@@ -0,0 +1,58 @@
import pyb
import lcd160cr
from random import randint, choice, uniform
lcd = lcd160cr.LCD160CR('X')
MAX_DEPTH = 4
RED = lcd.rgb(255, 0, 0)
YELLOW = lcd.rgb(255, 255, 0)
BLUE = lcd.rgb(0, 0, 255)
WHITE = lcd.rgb(255, 255, 255)
BLACK = lcd.rgb(0, 0, 0)
COLOURS = [RED, YELLOW, BLUE, WHITE, WHITE, WHITE]
class Node:
"""
A node in a tree representation of a Mondrian painting.
"""
def __init__(self, depth=0):
"""
Choose the colour of the rectangle, work out the depth
add child nodes if not too deep.
"""
self.colour = choice(COLOURS)
self.depth = depth + 1
self.children = []
if self.depth <= MAX_DEPTH:
self.direction = choice(['h', 'v'])
self.divide = uniform(0.1, 0.9)
self.children.append(Node(self.depth))
self.children.append(Node(self.depth))
def draw(self, x, y, w, h):
"""
Recursively draw this node and its children.
"""
lcd.set_pen(BLACK, self.colour)
lcd.rect(x, y, w, h)
if self.children:
if self.direction == 'h':
self.children[0].draw(x, y, int(w * self.divide), h)
self.children[1].draw(x + int(w * self.divide), y,
int(w * (1.0 - self.divide)), h)
else:
self.children[0].draw(x, y, w, int(h * self.divide))
self.children[1].draw(x, y + int(h * self.divide), w,
int(h * (1.0 - self.divide)))
while True:
# Keep re-drawing new Mondrian pictures every few seconds.
tree = Node()
tree.draw(0, 0, lcd.w, lcd.h)
pyb.delay(randint(4000, 8000))
@@ -0,0 +1,16 @@
import lcd160cr
import random
lcd = lcd160cr.LCD160CR('X')
lcd.erase()
while True:
r = random.randint(0, 255)
g = random.randint(0, 255)
b = random.randint(0, 255)
colour = lcd.rgb(r, g, b)
x = random.randint(0, lcd.w)
y = random.randint(0, lcd.h)
lcd.set_pixel(x, y, colour)
@@ -0,0 +1,12 @@
# Taken from REPL based example.
import pyb
blue = pyb.LED(4)
i = 0
while True:
pyb.delay(5)
i += 1
if i > 255:
i = 0
blue.intensity(i)
@@ -0,0 +1,67 @@
import neopixel
import audiobusio
import digitalio
import audioio
import time
from board import *
def countdown(np):
""" Uses the NeoPixels to display a countdown."""
# Start from an "off" state.
np.fill((0, 0, 0))
np.write()
for i in range(10):
np[i] = (0, 20, 0)
np.write()
time.sleep(0.5)
np.fill((0, 128, 0))
np.write()
def record():
""" Returns a buffer of recorded sound."""
buf = bytearray(8000)
with audiobusio.PDMIn(MICROPHONE_CLOCK, MICROPHONE_DATA) as mic:
mic.record(buf, len(buf))
return buf
def play(buf, freq):
"""
Play the referenced buffer of recorded sound at a certain
frequency.
"""
# Set the speaker ready for output.
speaker_enable = digitalio.DigitalInOut(SPEAKER_ENABLE)
speaker_enable.switch_to_output(value = True)
# Play the audio buffer through the speaker.
with audioio.AudioOut(SPEAKER, buf) as speaker:
speaker.frequency = freq
speaker.play()
# Block while the speaker is playing.
while speaker.playing:
pass
neopixels = neopixel.NeoPixel(NEOPIXEL, 10, auto_write=False)
button_a = digitalio.DigitalInOut(BUTTON_A)
button_a.pull = digitalio.Pull.DOWN
button_b = digitalio.DigitalInOut(BUTTON_B)
button_b.pull = digitalio.Pull.DOWN
countdown(neopixels)
audio_buffer = record()
neopixels.fill((0, 0, 0))
neopixels.write()
freq = 8000 # Default = normal speed.
if button_a.value:
freq = 12000 # Button A = chipmunk.
elif button_b.value:
freq = 6000 # Button B = Barry White.
play(audio_buffer, freq)
@@ -0,0 +1,29 @@
import neopixel
import time
import digitalio
from board import NEOPIXEL, BUTTON_A, BUTTON_B
np = neopixel.NeoPixel(NEOPIXEL, 10, auto_write=False)
button_a = digitalio.DigitalInOut(BUTTON_A)
button_a.pull = digitalio.Pull.DOWN
button_b = digitalio.DigitalInOut(BUTTON_B)
button_b.pull = digitalio.Pull.DOWN
clockwise = True
while True:
time.sleep(0.05)
if button_a.value:
clockwise = True
elif button_b.value:
clockwise = False
for i in range(10):
if clockwise:
i = 9 - i
for j in range(10):
np[j] = tuple((max(0, val - 64) for val in np[j]))
np[i] = (0, 0, 254)
np.write()
@@ -0,0 +1,20 @@
import neopixel
import time
import digitalio
from board import NEOPIXEL, SLIDE_SWITCH
np = neopixel.NeoPixel(NEOPIXEL, 10, auto_write=False)
switch = digitalio.DigitalInOut(SLIDE_SWITCH)
switch.pull = digitalio.Pull.UP
while True:
time.sleep(0.05)
for i in range(10):
if switch.value:
i = 9 - i
for j in range(10):
np[j] = tuple((max(0, val - 64) for val in np[j]))
np[i] = (0, 0, 254)
np.write()
@@ -0,0 +1,35 @@
import neopixel
import touchio
import digitalio
from board import *
# Stops the speaker crackling when touched.
spkr = digitalio.DigitalInOut(SPEAKER_ENABLE)
spkr.switch_to_output()
spkr.value = False
np = neopixel.NeoPixel(NEOPIXEL, 10, auto_write=False)
touch_a1 = touchio.TouchIn(A1)
touch_a3 = touchio.TouchIn(A3)
touch_a4 = touchio.TouchIn(A4)
touch_a6 = touchio.TouchIn(A6)
while True:
if touch_a4.value:
np[0] = (255, 0, 0)
np[1] = (255, 0, 0)
if touch_a6.value:
np[3] = (0, 255, 0)
np[4] = (0, 255, 0)
if touch_a1.value:
np[5] = (255, 255, 0)
np[6] = (255, 255, 0)
if touch_a3.value:
np[8] = (0, 0, 255)
np[9] = (0, 0, 255)
for j in range(10):
np[j] = tuple((max(0, val - 32) for val in np[j]))
np.write()
@@ -0,0 +1,9 @@
from machine import Pin
led = Pin(2, Pin.OUT)
button = Pin(14, Pin.IN, Pin.PULL_UP)
while True:
led.value(button.value())
Oops, something went wrong.

0 comments on commit 806a29e

Please sign in to comment.