So I am trying to replace a Logitech G13 with a creation of my own.
It will be used for gaming only on a PC. The G13 thumb stick can be used as a joystick or as 8 way keyboard input. I dont want any fancy stuff like an lcd or profile starage.
I am using a Teensy 3.2 , a Chinese pcb mounted thumb stick from Amazon, and Gateron 3 pin (which have 2 pins) linear black mechanical switches.
I want 21 keyboard inputs and an analog thumb stick that can be used as a joystick or keyboard input.
I have a 6 pin toggle switch that will give the thumb stick access to 4 pin on the Teensy 2 at a time.
I am a brick layer and an a little lost when it comes to coding but I am no slouch when it comes to soldering.
so far I have the keyboard part coded in an array that I basically copied from here
I used the Joystick example for the analog read, but whre do I go from here :smiley-eek
I found this but It looks messy to me, could I use another array?
Also, I know that using a matrix is what is typically done for keyboard input and that the Teensy 3.2 is overkill... but it has the pins to do it this way... am I loosing out on anything? Besides money...
#include <Keyboard.h>
int led = 13;
int timer = 1;
const int pinBtn1 = 0;
const int pinBtn2 = 1;
const int pinBtn3 = 2;
const int pinBtn4 = 3;
const int pinBtn5 = 4;
const int pinBtn6 = 5;
const int pinBtnTAB = 6;
const int pinBtnZ = 7;
const int pinBtnQ = 8;
const int pinBtnE = 9;
const int pinBtnF = 10;
const int pinBtnT = 11;
const int pinBtnSH = 12;
const int pinBtnX = 18;
const int pinBtnC = 19;
const int pinBtnV = 20;
const int pinBtnSP = 21;
const int pinBtnCTRL = 22;
const int pinBtnB = 23;
const int pinBtnG = 24;
const int pinBtnN = 25;
const int pinBtnENT = 28;
const byte BUTTON_PINS[] = {pinBtn1,pinBtn2, pinBtn3,pinBtn4, pinBtn5, pinBtn6, pinBtnTAB, pinBtnZ, pinBtnQ, pinBtnE, pinBtnF, pinBtnT, pinBtnSH, pinBtnX, pinBtnC, pinBtnV, pinBtnSP, pinBtnCTRL, pinBtnB, pinBtnG, pinBtnN, pinBtnENT};
const int NUMBUTTONS = sizeof BUTTON_PINS / sizeof BUTTON_PINS[0];
const short KEY_CODES[NUMBUTTONS] = {KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_TAB, KEY_Z, KEY_Q, KEY_E, KEY_F, KEY_T, MODIFIERKEY_LEFT_SHIFT, KEY_X, KEY_C, KEY_V, KEY_SPACE, MODIFIERKEY_LEFT_CTRL, KEY_B, KEY_G, KEY_N, KEY_ENTER};
byte PreviousButtonState[NUMBUTTONS];
int xVal = 0;
int yVal = 0;
void setup() {
for (byte i = 0; i < NUMBUTTONS; i++) {
pinMode(BUTTON_PINS[i], INPUT_PULLUP);
PreviousButtonState[i] = HIGH;
}
pinMode(A0, INPUT_PULLUP);
pinMode(A1, INPUT_PULLUP);
}
void loop() {
Joystick.X(analogRead(A0));
Joystick.Y(analogRead(A1));
for (byte i=0; i<NUMBUTTONS; i++) {
byte buttonState = digitalRead(BUTTON_PINS[i]);
if (buttonState != PreviousButtonState[i]){
PreviousButtonState[i] = buttonState;
if (buttonState) {
Keyboard.release(KEY_CODES[i]);
delay(timer);
} else {
Keyboard.press(KEY_CODES[i]);
delay(timer);
}
}
}
}