I have made a program to comunicate to my computer using Serial, I use the same syntax as the cvzone library (example: 0#1#5#5#), and I use multiple if to check my button states (I'm sure it can be more efficient, but that's not the point), and here's the problem, the first two are working, the last one is as well, but the third and fourth one are not working, they are not changing in the Serial data (all of them are wired in Pull Down).
// Librairies
// none
// Pin Assignement
// Keys
int CTRL = 1;
int SHIFT = 2;
int ALT = 3;
int SPACE = 4;
int _A = 5;
int _B = 6;
int _C = 7;
int _D = 8;
int _E = 9;
int _F = 10;
int _G = 11;
int _H = 12;
int _I = 13;
int _J = 14;
int _K = 15;
int _L = 16;
int _M = 17;
int _N = 18;
int _O = 19;
int _P = 20;
int _Q = 21;
int _R = 22;
int _S = 23;
int _T = 24;
int _U = 25;
int _V = 26;
int _W = 27;
int _X = 28;
int _Y = 29;
int _Z = 30;
// Buttons
#define BT0_p 49
#define BT1_p 50
#define BT2_p 51
#define BT3_p 52
#define BT4_p 53
// Variables
// Python Communication
int sendVals[5];
// Button States
bool BT0 = false;
bool BT1 = false;
bool BT2 = false;
bool BT3 = false;
bool BT4 = false;
// Macros
int Macro1 = _A;
int Macro2 = _B;
int Macro3 = _C;
int Macro4 = _D;
int Macro5 = _E;
void setup() {
Serial.begin(9600);
pinMode(BT0_p, INPUT);
pinMode(BT1_p, INPUT);
pinMode(BT2_p, INPUT);
pinMode(BT3_p, INPUT);
pinMode(BT4_p, INPUT);
}
void loop() {
sendVals[0] = 0;
sendVals[1] = 0;
sendVals[2] = 0;
sendVals[3] = 0;
sendVals[4] = 0;
BT0 = digitalRead(BT0_p);
BT1 = digitalRead(BT1_p);
BT2 = digitalRead(BT2_p);
BT3 = digitalRead(BT3_p);
BT4 = digitalRead(BT4_p);
if (BT0) { sendVals[0] = Macro1; }
if (BT1) { sendVals[1] = Macro2; }
if (BT2) { sendVals[2] = Macro3; }
if (BT3) { sendVals[3] = Macro4; }
if (BT4) { sendVals[4] = Macro5; }
Serial.print(sendVals[0]); Serial.print("#");
Serial.print(sendVals[1]); Serial.print("#");
Serial.print(sendVals[2]); Serial.print("#");
Serial.print(sendVals[3]); Serial.print("#");
Serial.print(sendVals[4]); Serial.println("#");
}
(Underscores before letter are to not mix them with internal arduino things in case there is)
To be more precise, sendVals[2] and sendVals[3] are not working.
Rather an overkill to save 5 yes/no high/low in 5 ints...
Could be saved in 1 byte....
But a simple cast would do to put it in 5 bools.
Without the cast (like it is now) it will work too, but according to some is undefined...
Resistors(330 Ohm) are wired Behring the pin (left of button) and to the gnd rail.
All red going to 5V.
Pins 49-53, buttons right to left.
And I'm using the 5V and GND pins from the side (where the pins 30-50 are)
Wiring looks OK, but some spots are difficult to see.
Another thing I previously overlooked.
What board do you use???
Most boards do not have pins with number 50 or higher....
If this is the problem, then it is surprising that some of the buttons do work...