Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Snow globe intruder alert system

Snow globe intruder alert system

Learn how to build a snow globe that sounds an alarm and flashes a red alert when intruders are about. Me and my six year old daughter designed and built this project to have fun with friends and learn a bit about computers along the way.

Marwan Alsabbagh

June 09, 2018
Tweet

More Decks by Marwan Alsabbagh

Other Decks in Technology

Transcript

  1. Parts Circuit Playground Express $25 Snow Globe Kit $5 AAA

    Battery Holder $3 Conductive Thread $5 Total: $38 (28.50 GBP)
  2. Circuit Playground API >>> from adafruit_circuitplayground.express import cpx >>> #

    speaker play tone at 800Hz for 500ms >>> cpx.play_tone(800, 0.5) >>> # set brightness for NeoPixels to 50 percent >>> cpx.pixels.brightness = 0.5 >>> # set first NeoPixel to the color red >>> cpx.pixels[0] = [255, 0, 0] >>> # set all 10 NeoPixels to the color green >>> cpx.pixels.fill([0, 255, 0]) >>> # check if slide switch is on or off >>> cpx.switch >>> True >>> # check if capacitive touch is detected on pad A2 >>> cpx.touch_A2 >>> False
  3. main function from adafruit_circuitplayground.express import cpx import time TONES =

    dict(low=800, high=960) RGB = dict(black=[0, 0, 0], blue=[0, 0, 255], green=[0, 255, 0], cyan=[0, 255, 255], red=[255, 0, 0], magenta=[255, 0, 255], yellow=[255, 255, 0], white=[255, 255, 255]) CYCLE = ['cyan', 'blue', 'magenta', 'red', 'green', 'yellow'] def beep(frequency=TONES['high']): cpx.play_tone(frequency, 0.4) def main(): cpx.pixels.brightness = 1.0 beep() while True: if cpx.switch: rainbow() else: detect() main()
  4. rainbow function from adafruit_circuitplayground.express import cpx import time TONES =

    dict(low=800, high=960) RGB = dict(black=[0, 0, 0], blue=[0, 0, 255], green=[0, 255, 0], cyan=[0, 255, 255], red=[255, 0, 0], magenta=[255, 0, 255], yellow=[255, 255, 0], white=[255, 255, 255]) CYCLE = ['cyan', 'blue', 'magenta', 'red', 'green', 'yellow'] def rainbow(): for color in CYCLE: for i in range(10): cpx.pixels[i] = RGB[color] time.sleep(0.3)
  5. detect and alarm function from adafruit_circuitplayground.express import cpx import time

    TONES = dict(low=800, high=960) RGB = dict(black=[0, 0, 0], blue=[0, 0, 255], green=[0, 255, 0], cyan=[0, 255, 255], red=[255, 0, 0], magenta=[255, 0, 255], yellow=[255, 255, 0], white=[255, 255, 255]) def alarm(): for i in range(3): cpx.pixels.fill(RGB['red']) beep(TONES['high']) cpx.pixels.fill(RGB['black']) beep(TONES['low']) def detect(): colors = ['green'] * 10 + ['black'] * 10 for color in colors: if cpx.touch_A2: alarm() cpx.pixels.fill(RGB[color]) time.sleep(0.05)
  6. REPL with a 6 year old • Command/Response • Math

    • Command history • Reduce Typing • Independent • learn about sound and light
  7. teach API >>> from teach import cpx, beep, led >>>

    # make speaker beep >>> beep() >>> # make speaker beep at 800Hz >>> beep(800) >>> # reduce brightness to a more comfortable level >>> cpx.pixels.brightness = 0.02 >>> # set first LED to white >>> led() >>> # set second LED to red >>> led('red', 1) >>> # set 1st LED to blue with hex color code >>> led('0000ff') >>> # set 1st LED to Magenta(red on, green off, blue on) >>> led('101')