Hallo zusammen,
kann mir jemand mit dem Sketch helfen?
wenn ich den Sketch mit allen voids teste, dann funktioniert die "checkMidi abfrage nur einmal.
alle anderen "voids" funktionieren weiterhin tadellos.
Sobald ich nur eine "void potisAbfragen" im laufenden Programm habe funktioniert auch die "checkMidi" Void tadellos. Ab zwei "voids potisAbfragen" hängt sich die MidiAbfrage wieder auf.
Ich finde den Fehler aber nicht.
Kann mir jemand dabei helfen???
int controlChange = 176; // MIDI Kanal 1
int controllerNummer [] = {50,51,52,53};
int controllerWert []= {0,0,0,0};
int controllerWertAlt []= {0,0,0,0};
int potiWert []= {0,0,0,0};
// LED Abfrage Midi Empfang
byte commandByte ; //Midi Empfang Daten Channal 1
byte channelByte; //Midi Daten CHxx
byte statusByte; //Midi Daten Status
byte cc = 176;
#include <Bounce2.h>
//Tastenabfrage 22-27 [6]
byte taste [] = {LOW,LOW,LOW,LOW,LOW,LOW};
byte tasteAlt [] = {LOW,LOW,LOW,LOW,LOW,LOW};
byte tastepin [] = {22,23,24,25,26,27};
boolean tasteGedrueckt [] = {false,false,false,false,false,false};
Bounce debounce22 = Bounce();
Bounce debounce23 = Bounce();
Bounce debounce24 = Bounce();
Bounce debounce25 = Bounce();
Bounce debounce26 = Bounce();
Bounce debounce27 = Bounce();
void setup() {
Serial.begin(9600);
Serial1.begin(31250); //Midi Ausgang
Serial2.begin(31250); //Midi Eingang
pinMode(22, INPUT);
pinMode(23, INPUT);
pinMode(24, INPUT);
pinMode(25, INPUT);
pinMode(26, INPUT);
pinMode(27, INPUT);
pinMode (8, OUTPUT);
pinMode (9, OUTPUT);
pinMode (10, OUTPUT);
pinMode (11, OUTPUT);
debounce22.attach(tastepin[0]);
debounce22.interval(5); // interval in ms
debounce23.attach(tastepin[1]);
debounce23.interval(5); // interval in ms
debounce24.attach(tastepin[2]);
debounce24.interval(5); // interval in ms
debounce25.attach(tastepin[3]);
debounce25.interval(5); // interval in ms
debounce26.attach(tastepin[4]);
debounce26.interval(5); // interval in ms
debounce27.attach(tastepin[5]);
debounce27.interval(5); // interval in ms
}
void loop() {
SerialLesen();
checkMIDI();
//potisAbfragen(0,0,A0);
//potisAbfragen(1,1,A1);
//potisAbfragen(2,2,A2);
potisAbfragen(3,3,A3);
Springe_zu_taster22(0,22);
Springe_zu_taster23(1,23);
Springe_zu_taster24(2,24);
Springe_zu_taster25(3,25);
Springe_zu_taster26(4,26);
Springe_zu_taster27(5,27);
}
void checkMIDI()
{
if ((commandByte == cc)&& (channelByte == 22)&& (statusByte == 1)){digitalWrite(8,HIGH);}
if ((commandByte == cc)&& (channelByte == 22)&& (statusByte == 0)){digitalWrite(8,LOW);}
if ((commandByte == cc)&& (channelByte == 23)&& (statusByte == 1)){digitalWrite(9,HIGH);}
if ((commandByte == cc)&& (channelByte == 23)&& (statusByte == 0)){digitalWrite(9,LOW);}
if ((commandByte == cc)&& (channelByte == 24)&& (statusByte == 1)){digitalWrite(10,HIGH);}
if ((commandByte == cc)&& (channelByte == 24)&& (statusByte == 0)){digitalWrite(10,LOW);}
if ((commandByte == cc)&& (channelByte == 25)&& (statusByte == 1)){digitalWrite(11,HIGH);}
if ((commandByte == cc)&& (channelByte == 25)&& (statusByte == 0)){digitalWrite(11,LOW);}
}
void SerialLesen() {
if (Serial2.available()==1) {
commandByte = Serial2.read();
Serial.println (commandByte);
delay (1);
channelByte = Serial2.read();
Serial.println (channelByte);
delay (1);
statusByte = Serial2.read();
Serial.println (statusByte);
{
while (Serial2.available() ==3);
} }}
void potisAbfragen(byte x,byte y,int analogPin){
potiWert[x] = analogRead(analogPin);
controllerWert[x] = map(potiWert[x],0,1023,0,127);
if (controllerWert[x] != controllerWertAlt[x]) {
sendeMIDI(controlChange, controllerNummer[y], controllerWert[x]); }
controllerWertAlt[x] = controllerWert[x];}
void Springe_zu_taster22(int x, int Nummer)
{ debounce22.update(); //debouncer
{ taste[x] = debounce22.read();
if (taste[x] == HIGH && tasteAlt[x] == LOW)
if (tasteGedrueckt[x] == false) { sendeMIDI(176,Nummer, 127);
tasteGedrueckt[x] = true; }
else { sendeMIDI(176, Nummer, 0);
tasteGedrueckt[x] = false;}
tasteAlt[x]= taste[x]; } }
void Springe_zu_taster23(int x, int Nummer)
{ debounce23.update(); //debouncer
{ taste[x] = debounce23.read();
if (taste[x] == HIGH && tasteAlt[x] == LOW)
if (tasteGedrueckt[x] == false) { sendeMIDI(176,Nummer, 127);
tasteGedrueckt[x] = true; }
else { sendeMIDI(176, Nummer, 0);
tasteGedrueckt[x] = false;}
tasteAlt[x]= taste[x]; }}
void Springe_zu_taster24(int x, int Nummer)
{ debounce24.update(); //debouncer
{ taste[x] = debounce24.read();
if (taste[x] == HIGH && tasteAlt[x] == LOW)
if (tasteGedrueckt[x] == false) { sendeMIDI(176,Nummer, 127);
tasteGedrueckt[x] = true; }
else { sendeMIDI(176, Nummer, 0);
tasteGedrueckt[x] = false;}
tasteAlt[x]= taste[x]; }}
void Springe_zu_taster25(int x, int Nummer)
{ debounce25.update(); //debouncer
{ taste[x] = debounce25.read();
if (taste[x] == HIGH && tasteAlt[x] == LOW)
if (tasteGedrueckt[x] == false) { sendeMIDI(176,Nummer, 127);
tasteGedrueckt[x] = true; }
else { sendeMIDI(176, Nummer, 0);
tasteGedrueckt[x] = false;}
tasteAlt[x]= taste[x]; }}
void Springe_zu_taster26(int x, int Nummer)
{ debounce26.update(); //debouncer
{ taste[x] = debounce26.read();
if (taste[x] == HIGH && tasteAlt[x] == LOW)
if (tasteGedrueckt[x] == false) { sendeMIDI(176,Nummer, 127);
tasteGedrueckt[x] = true; }
else { sendeMIDI(176, Nummer, 0);
tasteGedrueckt[x] = false;}
tasteAlt[x]= taste[x]; }}
void Springe_zu_taster27(int x, int Nummer)
{ debounce27.update(); //debouncer
{ taste[x] = debounce27.read();
if (taste[x] == HIGH && tasteAlt[x] == LOW)
if (tasteGedrueckt[x] == false) { sendeMIDI(176,Nummer, 127);
tasteGedrueckt[x] = true; }
else { sendeMIDI(176, Nummer, 0);
tasteGedrueckt[x] = false;}
tasteAlt[x]= taste[x]; }}
void sendeMIDI(int statusByte, int dataByte1, int dataByte2) {
Serial1.write(statusByte);
Serial1.write(dataByte1);
Serial1.write(dataByte2);}