/*
keyboard - modified.
Plays a pitch that changes based on a changing analog input from a FSR and a photo cell
circuit:
* 1 photocell
* 3 10K resistors
* 8-ohm speaker on digital pin 8
created 21 Jan 2010
Modified 4 Sep 2010
by Tom Igoe
This example code is in the public domain.
http://arduino.cc/en/Tutorial/Tone3
*/
#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_B0, NOTE_B4,NOTE_C3 };
void setup() {
}
void loop() {
//for (int thisSensor = 0; thisSensor < 3; thisSensor++) {
// get a sensor reading:
int fsrSensor = 0;
int sensorReading = analogRead(fsrSensor);
int photoSensor1 = 1;
int photo1 = analogRead(photoSensor1);
// int photoSensot2 = 2;
// int photo2 = analogRead(photoSensor2);
// int phototSensor3 = 3;
// int photo3 = analogRead(photoSensor3);
// if the sensor is pressed hard enough:
if (sensorReading > 896 ) {
// play the note corresponding to this sensor:
tone(8, NOTE_B0, 100);
}
else if (sensorReading > 768){
tone(8, NOTE_B1, 100);
}
else if (sensorReading > 640){
tone(8, NOTE_B2, 100);
}
else if (sensorReading > 512){
tone(8, NOTE_B3, 100);
}
else if (sensorReading > 384){
tone(8, NOTE_B4, 100);
}
else if (sensorReading > 256){
tone(8, NOTE_B5, 100);
}
else if (sensorReading > 128){
tone(8, NOTE_B6, 100);
}
else if (sensorReading > 10){
tone(8, NOTE_B7, 100);
}
else if (photo1 > 896 ) {
// play the note corresponding to this sensor:
noTone(8); // it will depend on the light conditions
//tone(8, NOTE_C1, 100);
}
else if (photo1 > 768){
// tone(8, NOTE_C2, 100);
noTone(8);
}
else if (photo1 > 640){
//tone(8, NOTE_C3, 100);
noTone(8);
}
else if (photo1 > 512){
//tone(8, NOTE_C4, 100);
noTone(8);
}
else if (photo1 > 384){
tone(8, NOTE_C5, 100);
}
else if (photo1 > 256){
tone(8, NOTE_C6, 100);
}
else if (photo1 > 128){
tone(8, NOTE_C7, 100);
}
else if (photo1 > 10){
tone(8, NOTE_C8, 100);
}
//}
Serial.println();
}