Courtesy of Pimoroni
Guide by Tanya Fish
This is a tutorial to use with an Explorer HAT Pro and some foamy sweets to make a silly Halloween interactive. Once Halloween is over, or the amusement value fades, you can try triggering lights or motors with other squishy sweets.
This was first made by Emma here at Pimoroni Towers, but she's given me the rest of the squishy sweets and her code, so you get this tutorial. Woo!
First, you need...
Put the resistor and buzzer into the breadboard of your Explorer HAT Pro, as shown in the picture below.
Using jumper jerky, plug one side into GND (ground) and the other into PWM (pulse width modulation) - this makes the circuit for turning the buzzer on and off. PWM means we can do a variety of different frequencies to make the buzzer sound different.
If you've ever wondered what a breadboard actually does, it's a lazy way of connecting circuits. It's just a series of clips hidden under the plastic.
Now to make the eyeball switches. Clip one end of the wire to pad 5 on the Explorer Hat, and the other end needs to be wedged firmly into the sweet.
Do the same with the other wire, this time clipping it to pad 8. You can use other pads, but you'll need to change the code.
Now all the hardware is set up, you need to get some code together to make it work.
Handily, we've written some below, with comments so you can hopefully understand what each bit does. You don't need the comments if you're typing it out.
import RPi.GPIO as GPIO
# Sets up GPIO pin 18 as the PWM out with a frequency of 60Hz
buzzer = GPIO.PWM(18,60)
# Uses a try to keep looking out for eye squishes on the 5 and 8 bare touch pads.
# Change the numbers if you use different ones.
# You could add more eyes or squishies in if you copy the block for a touch pad and
# add it into the while True loop with a different frequency in the brackets.
# Best not to go over 500 unless you're a bat or a dog or something
# If you change the sleep time to a bigger number it will stay on for longer.
# This bit means you can stop the program by pressing ctrl and c.
# And this bit cleans up before you leave the place in a right state
# because no one needs telling off.
Time to run the code and poke some eyes (we are not responsible for you poking the wrong eyes!)
Once you have the hang of it, try changing the frequencies, or add more squishy eye switches. Maybe you could make it into a Halloween make of your own!?