This repository has been archived on 2022-07-04. You can view files and clone it, but cannot push or open issues or pull requests.
controlbox/main.ino

52 lines
1.2 KiB
Arduino
Raw Normal View History

2021-01-30 14:22:10 +01:00
#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
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
2021-01-30 14:22:10 +01:00
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
2021-01-30 14:22:10 +01:00
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);
int state = digitalRead(BR[j]);
if (state != Bstate[j][i]) {
Joystick.setButton(BK[j][i], state);
Bstate[j][i] = state;
}
2021-01-30 14:22:10 +01:00
pinMode(BR[j], INPUT);
}
pinMode(BC[i], INPUT);
}
}
void readEncoders() {
}
2021-01-30 14:22:10 +01:00
void loop() {
readMatrix();
}