Skip to content

Instantly share code, notes, and snippets.

@jellea
Created January 13, 2019 17:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jellea/12f88d99a2bb692dc4537270c3884a99 to your computer and use it in GitHub Desktop.
Save jellea/12f88d99a2bb692dc4537270c3884a99 to your computer and use it in GitHub Desktop.
Penti chorded keyboard emulation for one half of the Let's Split 40% mech keyboard
#include <Keyboard.h>
#define ROW_NUM 5
#define COL_NUM 6
byte row_pins[5] = { 4, 6, 7, 8, 9 };
byte col_pins[6] = { 10, 16, 14, 15, 18, 19};
byte fingers[5][2] = {{4, 2},{3, 2}, {2, 2}, {1, 2}, {0, 4}}; // [col, row]
char finger_keys[5] = {'A', 'B', 'C', 'D', 'E'};
void setup() {
Serial.begin(9600);
}
char Penti[32] = {
0, 'N', 'I', 'G', 'E', 0, 'O', 'M',
'S', 'J', 'C', 'V', 'L', 0, 'U', 'K',
' ', 'D', 'A', 'Y', 'R', 0, 'B', 'T',
'F', 'H', 'Q', 'X', 'Z', 0, 'P', 'W'
};
void scan () {
static byte state;
byte newState = 0;
for (byte finger = 0; finger < 5; finger++){
byte col = fingers[finger][0];
byte row = fingers[finger][1];
pinMode(row_pins[row], OUTPUT);
digitalWrite(row_pins[row], LOW);
pinMode(col_pins[col], INPUT_PULLUP);
delayMicroseconds(30);
if (digitalRead(col_pins[col]) == LOW) {
newState = newState | (1 << finger);
}
pinMode(row_pins[row], INPUT_PULLUP);
}
if (newState == 0 && state != 0) { // Release
Keyboard.write(Penti[state]);
state = 0;
} else {
state = state | newState;
}
}
void loop() {
scan();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment