Added button matrix basic code
This commit is contained in:
parent
255aa7ce7d
commit
c60cb05fd5
1 changed files with 42 additions and 0 deletions
42
main.ino
Normal file
42
main.ino
Normal 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();
|
||||
}
|
Reference in a new issue