/* capteur branché avec sortie sur pin24 arduino */ bool EtatEntree24 = HIGH ; bool VarSuivi24 = HIGH ; bool EtatEntree26 = HIGH ; bool VarSuivi26 = HIGH ; bool EtatEntree28 = HIGH ; bool VarSuivi28 = HIGH ; void setup() { pinMode(24,INPUT); pinMode(26,INPUT); pinMode(28,INPUT); Serial.begin(31250); /* initialisation d'un port serie au debit MIDI */ noteOn(0x80, 0x24 , 0x00 ) ; /* note off sur canal1 ; C2 ; vel 0 */ noteOn(0x80, 0x26 , 0x00 ) ; /* note off sur canal1 ; D2 ; vel 0 */ noteOn(0x80, 0x28 , 0x00 ) ; /* note off sur canal1 ; E2 ; vel 0 */ } void noteOn(int cmd, int pitch, int velocity) /* plays a MIDI note. Doesn't check to see that cmd is greater than 127, or that data values are less than 127 */ { Serial.write(cmd); Serial.write(pitch); Serial.write(velocity); } void loop() { EtatEntree24 = digitalRead(24); EtatEntree26 = digitalRead(26); EtatEntree28 = digitalRead(28); if ( (EtatEntree24 != VarSuivi24) && (EtatEntree24 == HIGH) ) { noteOn(0x80, 0x24 , 0x00) ; /* note off sur canal1 ; C2 ; vel 0 */ /* Serial.println("touche lachee"); */ VarSuivi24 = HIGH; } if ( (EtatEntree24 != VarSuivi24) && (EtatEntree24 == LOW) ) { noteOn(0x90, 0x24 , 0x70) ; /* note on sur canal1 ; C2 ; vel */ /* Serial.println("touche appuyee"); */ VarSuivi24 = LOW; } if ( (EtatEntree26 != VarSuivi26) && (EtatEntree26 == HIGH) ) { noteOn(0x80, 0x26 , 0x00) ; /* note off sur canal1 ; D2 ; vel 0 */ /* Serial.println("touche lachee"); */ VarSuivi26 = HIGH; } if ( (EtatEntree26 != VarSuivi26) && (EtatEntree26 == LOW) ) { noteOn(0x90, 0x26 , 0x70) ; /* note on sur canal1 ; D2 ; vel */ /* Serial.println("touche appuyee"); */ VarSuivi26 = LOW; } if ( (EtatEntree28 != VarSuivi28) && (EtatEntree28 == HIGH) ) { noteOn(0x80, 0x28 , 0x00) ; /* note off sur canal1 ; C2 ; vel 0 */ /* Serial.println("touche lachee"); */ VarSuivi28 = HIGH; } if ( (EtatEntree28 != VarSuivi28) && (EtatEntree28 == LOW) ) { noteOn(0x90, 0x28 , 0x70) ; /* note on sur canal1 ; C2 ; vel */ /* Serial.println("touche appuyee"); */ VarSuivi28 = LOW; } /* // play notes from F#-0 (0x1E) to F#-5 (0x5A): for (int note = 0x1E; note < 0x5A; note ++) { //Note on channel 1 (0x90), some note value (note), middle velocity (0x45): noteOn(0x90, note, 0x45); delay(100); //Note on channel 1 (0x90), some note value (note), silent velocity (0x00): noteOn(0x90, note, 0x00); delay(100); */ }