Hardware 18
Hardware
3.7 Using an input to do something
An input allows a person to interact with the Galileo. To explore inputs, we can start playing and messing with
them. This is one suggestion for a project using inputs:
Make a musical instrument!
First, wire up your input so you can see the LED change if you interact with it. I started with a photodiode for
my project.
In order to hear something, you have to make a speaker. If you happen to have computer speakers, you can
try hooking alligator clips to dierent parts of the bands, and connecting them to where your LED goes (you
can remove the LED). You might hear an annoying pitched noise, which is a good sign!
I didn’t have a speaker ready, so I made one. Loop rubber coated electrical wire in a small circle about twenty
times (~1 in diameter). Strip the two ends of the wire, and leave them pointed outward, so you can connect to
them. Get a plastic cup and two magnets, place one magnet on the inside of the cup, on the bottom. Place
the other magnet underneath the cup, so the magnets stick to each other through the cup. Tape the loop
of the wire to the outside bottom of the cup, so that the magnets are in the center of the loop. Connect one
side of the wire to GND on your Galileo board, and the other to your output pin. When you upload the input
program (above), you should hear a high pitched noise. That means it’s working!
Try interacting with your input (i.e. shining light on the photodiode). Does the sound change? It should!
This gave me a little more variety in the sounds I produced. Try things to see if they make an interesting musi-
cal instrument. My nal loop function looked liked this:
voidloop(){
//putyourmaincodehere,torunrepeatedly:
intavalue;//Analogvaluereadfrompin
intscaledvalue;//valueafterscaling(dependsonyourinput)
avalue=analogRead(motorin)+analogRead(lightin);//addthevalues
fromthemotorandthediode
Serial.println(avalue);//printoutthatvaluetotheserialmonitor,
thisisformakingsuretheanaloginputisworking
//continuedonnextpage------>
I also messed with the delay, to make the noise more interesting, I added this line to the end of loop:
delay(map(avalue,0,1024+1024,0,100);