Dear Members,
Im a newbie in programming arduino. I just created a code to grab piezo sensors and send the signal to different midi chanels. The same time i push the piezo a LED should glow. It works pretty well but i noticed that it don
t work when i hit 2 sensors the same time, Could you please help me with that issue? Furthermore I am shure that I could make the code more efficient by defining more variables. THX for help....Her is the code:
int noteOn = 144;
int piezo = A0;
int piezo1 = A1;
int piezo2 = A2;
int threshold = 500;//anything over fifty means we've hit the piezo
void setup(){
pinMode (2, OUTPUT);
pinMode (3, OUTPUT);
pinMode (4, OUTPUT);
Serial.begin(9600);
}
void loop(){
int piezoVal = analogRead(piezo);
int piezoVal1 = analogRead(piezo1);
int piezoVal2 = analogRead(piezo2);
if (piezoVal>threshold){
Serial.write (noteOn);
Serial.write (36);
Serial.write (127);
digitalWrite(2, LOW);
delay(100);
digitalWrite(2, HIGH);
}
if (piezoVal1>threshold){
Serial.write (noteOn);
Serial.write (37);
Serial.write (127);
digitalWrite(3, LOW);
delay(100);
digitalWrite(3, HIGH);
}
if (piezoVal2>threshold){
Serial.write (noteOn);
Serial.write (38);
Serial.write (127);
digitalWrite(4, LOW);
delay(100);
digitalWrite(4, HIGH);
}}