Compare commits
No commits in common. "main" and "master" have entirely different histories.
6 changed files with 110 additions and 97 deletions
|
@ -1,91 +0,0 @@
|
||||||
#include <Keyboard.h>
|
|
||||||
|
|
||||||
const byte BR[3] = {9,5,13}; // Button array rows
|
|
||||||
const byte BC[3] = {10,11,12}; // Button array columns
|
|
||||||
/*const byte BK[3][3] = {{KEY_KP_1,KEY_KP_2,KEY_KP_3},
|
|
||||||
{KEY_KP_4,KEY_KP_5,KEY_KP_6},
|
|
||||||
{KEY_KP_7,KEY_KP_8,KEY_KP_9}
|
|
||||||
}; // Buttons controller keys */
|
|
||||||
const byte BK[3][3] = {{KEY_F15,KEY_F16,KEY_F17},
|
|
||||||
{KEY_F18,KEY_F19,KEY_F20},
|
|
||||||
{KEY_F21,KEY_F22,KEY_F23}
|
|
||||||
}; // Buttons controller keys
|
|
||||||
bool Bstate[3][3] = {{0,0,0},{0,0,0},{0,0,0}}; // Buttons state
|
|
||||||
|
|
||||||
const byte RE[6][2] = {{8,2},{7,3},{6,4},{19,18},{21,20},{22,23}}; // Rotary encoders pins {A,B}
|
|
||||||
const byte REK[6][2] = {{9,10},{11,12},{13,14},{15,16},{17,18},{19,20}}; // Rotary encoders keys {-,+}
|
|
||||||
unsigned long REchange[6] = {0,0,0,0,0,0}; // Last RE change time
|
|
||||||
bool REstate[6] = {0,0,0,0,0,0}; // Rotary encoders state
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
for (int i = 0; i < 12; i++) {
|
|
||||||
pinMode(RE[i / 2][i % 2], INPUT_PULLUP);
|
|
||||||
}
|
|
||||||
for (int i = 0; i < 3; i++) {
|
|
||||||
pinMode(BR[i], INPUT);
|
|
||||||
pinMode(BC[i], INPUT_PULLUP);
|
|
||||||
}
|
|
||||||
for (int i = 0; i < 6; i++) {
|
|
||||||
pinMode(RE[i][0], INPUT_PULLUP);
|
|
||||||
pinMode(RE[i][1], INPUT_PULLUP);
|
|
||||||
}
|
|
||||||
|
|
||||||
Keyboard.begin();
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
readMatrix();
|
|
||||||
readEncoders();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Read temporary button matrix
|
|
||||||
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]) {
|
|
||||||
if (i == 0 && j == 0) {
|
|
||||||
setKey(BK[j][i], state);
|
|
||||||
} else {
|
|
||||||
setKey(BK[j][i], !state);
|
|
||||||
}
|
|
||||||
Bstate[j][i] = state;
|
|
||||||
}
|
|
||||||
pinMode(BR[j], INPUT);
|
|
||||||
}
|
|
||||||
pinMode(BC[i], INPUT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Press key
|
|
||||||
void setKey(byte key, bool state) {
|
|
||||||
if (state) {
|
|
||||||
Keyboard.press(key);
|
|
||||||
} else {
|
|
||||||
Keyboard.release(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void readEncoders() {
|
|
||||||
for (int i = 0; i < 6; i++) {
|
|
||||||
bool Astate = digitalRead(RE[i][0]);
|
|
||||||
|
|
||||||
if (Astate != REstate[i]) {
|
|
||||||
if (digitalRead(RE[i][1]) == Astate) {
|
|
||||||
Keyboard.press(KEY_LEFT_CTRL);
|
|
||||||
Keyboard.write(BK[1 + i / 3][i % 3]);
|
|
||||||
Keyboard.release(KEY_LEFT_CTRL);
|
|
||||||
} else {
|
|
||||||
Keyboard.press(KEY_LEFT_SHIFT);
|
|
||||||
Keyboard.write(BK[1 + i / 3][i % 3]);
|
|
||||||
Keyboard.release(KEY_LEFT_SHIFT);
|
|
||||||
}
|
|
||||||
REstate[i] = Astate;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
20
LICENSE
Normal file
20
LICENSE
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
This is free and unencumbered software released into the public domain.
|
||||||
|
|
||||||
|
Anyone is free to copy, modify, publish, use, compile, sell, or distribute
|
||||||
|
this software, either in source code form or as a compiled binary, for any
|
||||||
|
purpose, commercial or non-commercial, and by any means.
|
||||||
|
|
||||||
|
In jurisdictions that recognize copyright laws, the author or authors of this
|
||||||
|
software dedicate any and all copyright interest in the software to the public
|
||||||
|
domain. We make this dedication for the benefit of the public at large and
|
||||||
|
to the detriment of our heirs and successors. We intend this dedication to
|
||||||
|
be an overt act of relinquishment in perpetuity of all present and future
|
||||||
|
rights to this software under copyright law.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
||||||
|
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
|
||||||
|
THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. For more information,
|
||||||
|
please refer to <https://unlicense.org/>
|
3
README.md
Normal file
3
README.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# controlbox
|
||||||
|
|
||||||
|
Arduino code for custom controller box with 6 clickable rotary encoders and 3 buttons.
|
87
controlbox.ino
Normal file
87
controlbox.ino
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
#include <Joystick.h>
|
||||||
|
|
||||||
|
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,JOYSTICK_TYPE_GAMEPAD,
|
||||||
|
21, 0,
|
||||||
|
false, false, false,
|
||||||
|
false, false, false,
|
||||||
|
false, false,
|
||||||
|
false, false, false);
|
||||||
|
|
||||||
|
const byte BR[3] = {9,5,13}; // Button array rows
|
||||||
|
const byte BC[3] = {10,11,12}; // Button array columns
|
||||||
|
const byte BK[3][3] = {{0,1,2},{3,4,5},{6,7,8}}; // Buttons controller keys
|
||||||
|
bool Bstate[3][3] = {{0,0,0},{0,0,0},{0,0,0}}; // Buttons state
|
||||||
|
|
||||||
|
const byte RE[6][2] = {{8,2},{7,3},{6,4},{19,18},{21,20},{22,23}}; // Rotary encoders pins {A,B}
|
||||||
|
const byte REK[6][2] = {{9,10},{11,12},{13,14},{15,16},{17,18},{19,20}}; // Rotary encoders keys {-,+}
|
||||||
|
unsigned long REchange[6] = {0,0,0,0,0,0}; // Last RE change time
|
||||||
|
bool REstate[6] = {0,0,0,0,0,0};
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
for(int i=0; i<12; i++) {
|
||||||
|
pinMode(RE[i/2][i%2], INPUT_PULLUP);
|
||||||
|
}
|
||||||
|
for(int i=0; i<3; i++) {
|
||||||
|
pinMode(BR[i], INPUT);
|
||||||
|
pinMode(BC[i], INPUT_PULLUP);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i=0; i<6; i++) {
|
||||||
|
pinMode(RE[i][0], INPUT_PULLUP);
|
||||||
|
pinMode(RE[i][1], 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]) {
|
||||||
|
if (i==0 && j==0) {
|
||||||
|
Joystick.setButton(BK[j][i], state);
|
||||||
|
} else {
|
||||||
|
Joystick.setButton(BK[j][i], !state);
|
||||||
|
}
|
||||||
|
Bstate[j][i] = state;
|
||||||
|
}
|
||||||
|
pinMode(BR[j], INPUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
pinMode(BC[i], INPUT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void readEncoders() {
|
||||||
|
for (int i=0; i<6; i++) {
|
||||||
|
if (millis() - REchange[i] > 50) {
|
||||||
|
Joystick.releaseButton(REK[i][0]);
|
||||||
|
Joystick.releaseButton(REK[i][1]);
|
||||||
|
REchange[i] = millis();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i=0; i<6; i++) {
|
||||||
|
bool Astate = digitalRead(RE[i][0]);
|
||||||
|
|
||||||
|
if (Astate != REstate[i]) {
|
||||||
|
if(digitalRead(RE[i][1]) == Astate) {
|
||||||
|
Joystick.pressButton(REK[i][0]);
|
||||||
|
} else {
|
||||||
|
Joystick.pressButton(REK[i][1]);
|
||||||
|
}
|
||||||
|
REchange[i] = millis();
|
||||||
|
REstate[i] = Astate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
readMatrix();
|
||||||
|
readEncoders();
|
||||||
|
}
|
BIN
data/ArduinoJoystickLibrary-2.0.7.zip
Normal file
BIN
data/ArduinoJoystickLibrary-2.0.7.zip
Normal file
Binary file not shown.
|
@ -1,6 +0,0 @@
|
||||||
{
|
|
||||||
"cpu": {
|
|
||||||
"fqbn": "arduino:avr:micro",
|
|
||||||
"port": ""
|
|
||||||
}
|
|
||||||
}
|
|
Reference in a new issue