Hi!
I'm trying to build a simple laser harp with Arduino Leonardo and 8 laser and photoresistors.
An IR sensor (TL1838) allows to control notes and scales with my phone and an ultrasonic module (HC-SR04) controls the pitchbend and, i'm trying, the aftertouch when the distance is lower than 4cm.
I'm using the arduino MIDI library by FortySevenEffects but I don't understand how to use the MonoPhonic AfterTouch message (that applies to all notes)..
MonoPhonic AfterTouch function is described here
And here is my code for the HC-SR04 (with the NewPing library):
unsigned int uS = sonar.ping();
Dist = uS / US_ROUNDTRIP_CM;
if(Dist!=oldDist){
oldDist=Dist;
//Serial.println(Dist);
if(Dist>4){
pitch = map(Dist,5,50,-8192,8191);
MIDI.sendPitchBend(pitch, 1);
oldDist=Dist;
}
if(Dist==0) MIDI.sendPitchBend(0, 1);
if((Dist<=4)&&(Dist!=0)){
MIDI.sendAfterTouch(127, 1);
MIDI.sendPitchBend(0, 1);
}
}
The PitchBend works pretty well but the AfterTouch don't and I have no idea how to fix this..
The complete program is in the attachments
Any help appreciated, thanks a lot!
(and sorry for my bad english, I'm italian)
Midi_IR.ino (5.15 KB)