Hello!
I'm running this project that reads data from Piezo's and send over MIDI USB (MocoLufa) the signals of 3 notes (36,38,46 - Kick, Snare, HiHat).
Its works but when i press two or three piezos at the same time it only sends one note at time.
It would be nice to get some delay between instructions (150ms), but everytime i use delay instruction, the piezos doensn't respond well.
Can you help me?
This is my code:
#include <MIDI.h>
#include <midi_Defs.h>
#include <midi_Message.h>
#include <midi_Namespace.h>
#include <midi_Settings.h>#define CHANNEL 1
#define DEBOUNCE 30const int sensKC=0;
const int sensSN=1;
const int sensHH=2;MIDI_CREATE_DEFAULT_INSTANCE();
int thKC = 300;
int thSN = 400;
int thHH = 400;void setup() {
Serial.begin(31250);
MIDI.begin();}
void playKC(){
MIDI.sendNoteOn(36, 127, CHANNEL);
MIDI.sendNoteOff(36, 0, CHANNEL);}
void playSN(){
MIDI.sendNoteOn(38, 127, CHANNEL);
MIDI.sendNoteOff(38, 0, CHANNEL);}
void playHH(){
MIDI.sendNoteOn(46, 127, CHANNEL);
MIDI.sendNoteOff(46, 0, CHANNEL);}
void playKCSN() {
MIDI.sendNoteOn(36, 127, CHANNEL);
MIDI.sendNoteOn(38, 127, CHANNEL);
MIDI.sendNoteOff(36, 0, CHANNEL);
MIDI.sendNoteOff(38, 0, CHANNEL);
}void loop() {
int valKC= analogRead(sensKC);
int valSN= analogRead(sensSN);
int valHH= analogRead(sensHH);//KC
if ((valKC >= thKC) && (valSN < thSN) && (valHH < thHH)) {
playKC();
delay(150);}
//SN
if ((valSN >= thSN) && (valKC < thKC) && (valHH < thHH)) {
playSN();}
//HH
if ((valHH >= thHH) && (valKC < thKC) && (valSN < thSN)) {
playHH();}
}