HeiMa:
ja das array muss ich mir auch mal in Ruhe anschauen....
aber alles was ich da bisher versucht habe - hat nicht funktioniert.
Weil das dicke fette C++ Buch noch ungelesen in der Bücherei steht.
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
const byte cc = 176;
void sendeMIDI(int statusByte, int dataByte1, int dataByte2);
void potisAbfragen(byte x,byte y,int analogPin);
#include <Bounce2.h>
class Taster
{
private:
byte pin;
byte Nummer;
bool tasteAlt = false;
bool tasteGedrueckt = false;
Bounce debounce;
public:
Taster(byte pin,byte Nummer):pin(pin),Nummer(Nummer){}
void init()
{
pinMode(pin,INPUT);
debounce.attach(pin);
debounce.interval(5); // interval in ms
}
void run()
{
debounce.update(); //debouncer
bool taste = debounce.read();
if (taste == HIGH && tasteAlt == LOW)
{
if (tasteGedrueckt == false)
{
sendeMIDI(176,Nummer, 127);
tasteGedrueckt = true;
}
else
{
sendeMIDI(176, Nummer, 0);
tasteGedrueckt = false;
}
}
tasteAlt= taste;
}
};
Taster taster[] = {
{22,22},
{23,23},
{24,24},
{25,25},
{26,26},
{27,27},
} ;
void setup() {
Serial.begin(9600);
Serial1.begin(31250); //Midi Ausgang
Serial2.begin(31250); //Midi Eingang
for(Taster & taste:taster) taste.init();
pinMode (8, OUTPUT);
pinMode (9, OUTPUT);
pinMode (10, OUTPUT);
pinMode (11, OUTPUT);
}
void loop()
{
//potisAbfragen(0,0,A0);
//potisAbfragen(1,1,A1);
//potisAbfragen(2,2,A2);
potisAbfragen(3,3,A3);
for(Taster & taste:taster) taste.run();
}
void CmdParser(byte value)
{
static byte chanel;
enum Status{START,CHANEL,STATUS};
static Status status = START;
switch(status)
{
case START : if(cc == value) status = CHANEL;
break;
case CHANEL : if(value < 22 || value > 25)
{
status = START;
}else
{
chanel = value;
status = STATUS;
}
break;
case STATUS : if(value < 2)
{
byte pin;
if(chanel == 22) pin = 8;
if(chanel == 23) pin = 9;
if(chanel == 24) pin = 10;
if(chanel == 25) pin = 11;
digitalWrite(pin,value);
}
status = START;
break;
}
}
void serialEvent2()
{
while(Serial2.available()) CmdParser(Serial2.read());
}
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 sendeMIDI(int statusByte, int dataByte1, int dataByte2)
{
Serial1.write(statusByte);
Serial1.write(dataByte1);
Serial1.write(dataByte2);
}