2011-08-30 21:33:32 +02:00
|
|
|
/*
|
|
|
|
keyboard
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2011-08-30 21:33:32 +02:00
|
|
|
Plays a pitch that changes based on a changing analog input
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2011-08-30 21:33:32 +02:00
|
|
|
circuit:
|
2017-07-12 21:30:49 +02:00
|
|
|
- 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
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2011-08-30 21:33:32 +02:00
|
|
|
created 21 Jan 2010
|
2012-04-09 16:48:11 +02:00
|
|
|
modified 9 Apr 2012
|
2013-10-21 09:58:40 +02:00
|
|
|
by Tom Igoe
|
2011-08-30 21:33:32 +02:00
|
|
|
|
|
|
|
This example code is in the public domain.
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2015-05-20 17:10:06 +02:00
|
|
|
http://www.arduino.cc/en/Tutorial/Tone3
|
2013-10-21 09:58:40 +02:00
|
|
|
|
2011-08-30 21:33:32 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#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[] = {
|
2013-10-21 09:58:40 +02:00
|
|
|
NOTE_A4, NOTE_B4, NOTE_C3
|
|
|
|
};
|
2011-08-30 21:33:32 +02:00
|
|
|
|
|
|
|
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);
|
2013-10-21 09:58:40 +02:00
|
|
|
}
|
2011-08-30 21:33:32 +02:00
|
|
|
}
|
|
|
|
}
|