Added button matrix basic code

This commit is contained in:
Edgar P. Burkhart 2021-01-30 14:22:10 +01:00
parent 255aa7ce7d
commit c60cb05fd5
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227

42
main.ino Normal file
View file

@ -0,0 +1,42 @@
#include <Joystick.h>
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 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
void setup() {
for(int i=0; i<6; i++) {
pinMode(REl[i], INPUT_PULLUP);
pinMode(REr[i], INPUT_PULLUP);
}
for(int i=0; i<6; i++) {
pinMode(BR[i], INPUT);
pinMode(BC[i], INPUT_PULLUP);
}
Joystick.begin()
}
void readMatrix() {
for (int i=0; i<3; i++) {
pinMode(BC[i], OUTPUT);
digitalWrite(BC[i], LOW);
for (int j=0; j<3; j++) {
pinMode(BR[j], INPUT_PULLUP);
keys[i][j] = digitalRead(BR[j]);
pinMode(BR[j], INPUT);
}
pinMode(BC[i], INPUT);
}
}
void loop() {
readMatrix();
}