Updated button matrix function with Joystick functionality

This commit is contained in:
Edgar P. Burkhart 2021-01-30 14:46:05 +01:00
parent c60cb05fd5
commit 745e98f0ae
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227

View file

@ -4,10 +4,12 @@ Joystick_ Joystick;
const byte BR[3] = {1,2,3}; // Button array rows
const byte BC[3] = {4,5,6}; // Button array columns
byte keys[3][3];
const byte BK[3][3] = {{1,2,3},{4,5,6},{7,8,9}}; // Buttons controller keys
const bool Bstate[3][3] = {{0,0,0},{0,0,0},{0,0,0}}; // Buttons state
const byte REA[6] = {7,8,9,10,11,12}; // Rotary encoders pin A
const byte REB[6] = {13,14,15,16,17,18}; // Rotary encoders pin B
const byte RE[6][2] = {{7,8},{9,10},{11,12},{13,14},{15,16},{17,18}}; // Rotary encoders pins {A,B}
const byte REK[6][2] = {{10,11},{12,13},{14,15},{16,17},{18,19},{20,21}}; // Rotary encoders keys {-,+}
const bool REstate[6][2] = {{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}}; // Rotary encoders state
void setup() {
for(int i=0; i<6; i++) {
@ -29,7 +31,11 @@ void readMatrix() {
for (int j=0; j<3; j++) {
pinMode(BR[j], INPUT_PULLUP);
keys[i][j] = digitalRead(BR[j]);
int state = digitalRead(BR[j]);
if (state != Bstate[j][i]) {
Joystick.setButton(BK[j][i], state);
Bstate[j][i] = state;
}
pinMode(BR[j], INPUT);
}
@ -37,6 +43,10 @@ void readMatrix() {
}
}
void readEncoders() {
}
void loop() {
readMatrix();
}