This piezo midi drums are my school project. For now I have just one "drum". My Arduino sends a signal to Serial to MIDI Coverter then via LoopBe1 to Native Instruments:Traktor.
I have one serious problem. When I hit the piezo I get multiply values, sometimes it's even 20 values . Program should search for maximum value
I hope you can help me.
here is my code:
int ledPin = 12;
int piezo = A0;
int threshold = 100;
int sensorReading = 0;
int i=0,MAX=0;
Do you have some protection at the input of the Arduino ?
Do you connect the piezo in such a way that a positive pulse is generated ? Or could it also be a negative pulse ?
You use a threshold, and if the input signal is above that, it is considered a valid pulse. Waiting for the maximum value seems not right to me.
But for each drum, you could add a variable called 'active'. That variable is 'true' while the pulse is still busy, and 'false' is the pulse is below the threshold again. That way just one midi TX is sent for each pulse, no matter how long the pulse is.
Another way to do this, is to use timing with the millis() function. You can use it to make a new pulse is only valid after about 100ms.
The best way is perhaps both. Use the variable 'active' together with the timing.
now it works almost fine. there is one problem with latency. I hit the piezo, but sound is delayed by 500 milliseconds approx. do you think that problem is with converter or virtual midi interface or software that plays samples?
code:
int ledPin = 12;
int piezo = A0;
int threshold = 200;
int sensorReading = 0;
int val,oldcas,cas;