code for a one octave sensor board
/*
keyboard
Plays a pitch that changes based on a changing analog input
circuit:
* 13 force-sensing resistors from +5V to analog in 0 through 5
* 13 10K resistors from analog in 0 through 5 to ground
* 8-ohm speaker on digital pin 8
created 21 Jan 2010
by Tom Igoe
*/
#include "pitches.h"
const int threshold = 10; // minimum reading of the sensors that generates a note
// notes to play, corresponding to the 3 sensors:
int notes[] = {
NOTE_C4, NOTE_CS4, NOTE_D4, NOTE_D#4, NOTE_E4, NOTE_F4, NOTE_FS4, NOTE_G4, NOTE_GS4, NOTE_A4, NOTE_AS4, NOTE_B4, NOTE_C3 };
void setup() {
}
void loop() {
for (int thisSensor = 0; thisSensor < 13; 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();
}