We followed the first Tech Will Save Us' first step ('The Jar') to set up our jar - coincidentally we had exactly the same jar. We found their instructions and pictures a little bit unclear, so we'll mention that we bend the copper tape back on itself to make a loop to clip the crocodile clips onto:
We also went for different wiring. Our wiring diagram looks like this:
And that looks like this when we wired it up for real on the micro:bit:
Here's our complete code:
""" Micro Alarm Inspired by http://make.techwillsaveus.com/projects/microguardian Makes the micro_bit into an alarm. Sets up a connection between pin 0 and 3v. When that connection is broken we trigger output on pin1, which should be connected to a buzzer. Developed by http://giggletronics.blogspot.co.uk/ This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. https://creativecommons.org/licenses/by-nc-sa/4.0/ """ from microbit import * # We define two variables that give more meaningful names to the micro:bit's IO pins contact = pin0 buzzer = pin1 # Main loop while True: # Is the contact open(0) or closed(1)? if contact.read_digital() == 0: # Open - Make a beeping noise and show that the micro:bit is angry # Turn buzzer on, show angry face and wait for 1/4 second buzzer.write_digital(1) display.show(Image.ANGRY) sleep(250) # Turn buzzer off, show sword and wait for 1/4 second buzzer.write_digital(0) display.show(Image.SWORD) sleep(250) else: # Closed - Show that the micro:bit is asleep display.show(Image.ASLEEP)
Python and hex files as per usual:
micro_alarm.py
micro_alarm.hex
No comments:
Post a Comment