my problem is that the programm always sends signals, even if the values in controllerWert dont get changed. The goal should be that the programm only send signals, when the values get changed and stop after that. My guess is that there is a problem with the if in line 59. I also tried puting line 63 before the if to check if i made any misstakes with the double-array, but as expected then there were no signals send.The hardware seems to work fine. I hope someone can help
#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
// Analoge Controller
int controlChange = 176; // MIDI Kanal 1
int multiplexPin[] = {A0, A1, A2, A3, A4, A5};
int controllerWert[6][8];
int controllerWertAlt[6][8];
int potiWert[] = {0, 0, 0, 0, 0, 0};
int select1 = 0;
int select2 = 0;
int select3 = 0;
int controllerNummer[16];
// Zähler
int i = 0; //AnalogIn A0-A5
int iM = 0; //Multiplexer 4051
void setup() {
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("MIDI-Controller");
delay(1000);
lcd.setCursor(0, 1);
lcd.print("by Markus Hunke");
//lcd.clear();
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
Serial.begin(9600);
for (int x = 0; x < 16; x++) {
controllerNummer[x] = 21 + x;
}
}
void loop() {
for (i = 0; i <= 1; i++) {
for (iM = 0; iM <= 7; iM++) {
select1 = bitRead(iM, 0);
select2 = bitRead(iM, 1);
select3 = bitRead(iM, 2);
digitalWrite(8, select1);
digitalWrite(9, select2);
digitalWrite(10, select3);
potiWert[i] = analogRead(multiplexPin[i]);
controllerWert[i][iM] = map(potiWert[i], 0, 1023, 0, 127);
if (controllerWert[i][iM] != controllerWertAlt[i][iM]){
Serial.write(controlChange);
Serial.write(controllerNummer[i * 8 + iM]);
Serial.write(controllerWert[i][iM]);
controllerWertAlt[i][iM] = controllerWert[i][iM];
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire