#include <Tone.h>
#define ERROR_WINDOW 50
int notes[] = { NOTE_A3,
NOTE_B3,
NOTE_C4,
NOTE_D4,
NOTE_E4,
NOTE_F4,
NOTE_G4,
NOTE_A4,
NOTE_B4,
NOTE_C5};
// You can declare the tones as an array
Tone Sounds[2];
void setup(void){
Serial.begin(9600);
Sounds[0].begin(9);
Sounds[1].begin(10);
}
void loop(void){
char c;
int val=analogRead(A0);
int val2=analogRead(A1);
Serial.print("val1=");
Serial.println(val);
delay(100);
if(val<50){
Sounds[0].play(notes[8]);
}else if(val<65){
Sounds[0].play(notes[7]);
}else if(val<75){
Sounds[0].play(notes[6]);
}else if(val<90){
Sounds[0].play(notes[5]);
}else if(val<150){
Sounds[0].play(notes[4]);
}else if( val<200){
Sounds[0].play(notes[3]);
}else if( val<250){
Sounds[0].play(notes[2]);
}else if( val<300){
Sounds[0].play(notes[1]);
}else {
Sounds[0].stop();
}
if(val2<50){
Sounds[1].play(notes[0]);
}else if(val2<75){
Sounds[1].play(notes[1]);
}else if(val2<100){
Sounds[1].play(notes[2]);
}else if(val2<150){
Sounds[1].play(notes[3]);
}else if(val2<200){
Sounds[1].play(notes[4]);
}else if( val2<250){
Sounds[1].play(notes[5]);
}else if( val2<300){
Sounds[1].play(notes[6]);
}else if( val2<400){
Sounds[1].play(notes[7]);
}else {
Sounds[1].stop();
}
}
A Digital Theremin by JG from SACC-PC on Vimeo.