This example is for Wiring version 1.0 build 0100+. If you have a previous version, use the examples included with your software. If you see any errors or have comments, please let us know.
keyboard by Tom Igoe
Plays a pitch that changes based on a changing analog input circuit: 3 force-sensing resistors from +5V to analog in 0 through 5 3 10K resistors from analog in 0 through 5 to ground 8-ohm speaker on digital pin 8
Plays a pitch that changes based on a changing analog input circuit: 3 force-sensing resistors from +5V to analog in 0 through 5 3 10K resistors from analog in 0 through 5 to ground 8-ohm speaker on digital pin 8
const int threshold = 10; // minimum reading of the sensors that generates a note // notes to play, corresponding to the 3 sensors: int notes[] = { NOTE_A4, NOTE_B4, NOTE_C3 }; void setup() { } void loop() { for (int thisSensor = 0; thisSensor < 3; thisSensor++) { // get a sensor reading: int sensorReading = analogRead(thisSensor); // if the sensor is pressed hard enough: if (sensorReading > threshold) { // play the note corresponding to this sensor: tone(8, notes[thisSensor], 20); } } Serial.println(); }