Updated button matrix function with Joystick functionality
This commit is contained in:
parent
c60cb05fd5
commit
745e98f0ae
1 changed files with 14 additions and 4 deletions
18
main.ino
18
main.ino
|
@ -4,10 +4,12 @@ Joystick_ Joystick;
|
||||||
|
|
||||||
const byte BR[3] = {1,2,3}; // Button array rows
|
const byte BR[3] = {1,2,3}; // Button array rows
|
||||||
const byte BC[3] = {4,5,6}; // Button array columns
|
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 RE[6][2] = {{7,8},{9,10},{11,12},{13,14},{15,16},{17,18}}; // Rotary encoders pins {A,B}
|
||||||
const byte REB[6] = {13,14,15,16,17,18}; // Rotary encoders pin 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() {
|
void setup() {
|
||||||
for(int i=0; i<6; i++) {
|
for(int i=0; i<6; i++) {
|
||||||
|
@ -29,7 +31,11 @@ void readMatrix() {
|
||||||
|
|
||||||
for (int j=0; j<3; j++) {
|
for (int j=0; j<3; j++) {
|
||||||
pinMode(BR[j], INPUT_PULLUP);
|
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);
|
pinMode(BR[j], INPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +43,10 @@ void readMatrix() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void readEncoders() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
readMatrix();
|
readMatrix();
|
||||||
}
|
}
|
Reference in a new issue