Hi all,
I try to programe a small Arduino code. It simply should send different MIDI out (NoteOns) in certain ranges of the analogIn data.
This works great with if else....
But it loops very fast.
I need only one MidiOut (NoteOn), when the analogIn changes (or a new range is achieved).
How can I do this???
I do not want to do it with delay etc...
I tried it with the following code below, but doesn't work...
Thank you very much,
Thomas
// Variables:
char noteOld = 0;
char note = 0; // The MIDI note value to be played
int AnalogValue = 0; // value from the analog input
void setup() {
// Set MIDI baud rate:
Serial.begin(31250);
}
void loop() {
// potentiometer range from 0 to 1023:
AnalogValue = analogRead(0);
if ( AnalogValue > 200 && noteOld != 0x41)
{
note = 0x41;
noteOn(0x90, note, 0x40);
note = noteOld;
}
else
{
note = 0x48;
noteOn(0x90, note, 0x40);
note = noteOld;
}
}
// noteOn(0x90, note, 0x40);
void noteOn(char cmd, char data1, char data2) {
Serial.print(cmd, BYTE);
Serial.print(data1, BYTE);
Serial.print(data2, BYTE);
}