Skip to content

Commit afb7bfd

Browse files
committed
feat: basic working example
1 parent ef78b85 commit afb7bfd

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

drivekeys.ino

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
**/
1919

2020
// Aesthetics
21-
#define TAP_MS 200 // When a tap becomes a hold in milliseconds
21+
#define TAP_MS 20 // When a tap becomes a hold in milliseconds
2222

2323
// MAX_KEYS must be larger than the highest IO pin on the board used for keymapping
2424
// In this case it's digital pin 13. 20 > 13, so MAX_KEYS of 20 is fine.
@@ -35,7 +35,7 @@ static bool STATE_MAP[MAX_KEYS];
3535
#define KEY_C 11
3636
#define KEY_D 10
3737
#define KEY_E 9
38-
#define KEY_F 8
38+
#define KEY_F 6
3939

4040
void setup() {
4141
// Assign each key to produce a character output.
@@ -71,39 +71,38 @@ void setup() {
7171
pinMode(KEY_E, INPUT_PULLUP);
7272
pinMode(KEY_F, INPUT_PULLUP);
7373

74-
75-
76-
// Keyboard.begin();
74+
Keyboard.begin();
7775
Serial.begin(9600);
78-
delay(5000);
76+
// delay(5000);
7977
Serial.println("Begin!");
8078
}
8179

82-
void stateCheck(int incomingKey, char* output) {
80+
void stateCheck(int incomingKey) {
8381
bool incoming = digitalRead(incomingKey);
8482

8583
if (incoming == STATE_MAP[incomingKey]) {
8684
return;
8785
}
8886

89-
strcat(output, &KEY_MAP[incomingKey]);
90-
87+
if (incoming == LOW) {
88+
Serial.print("X ");
89+
Serial.println(KEY_MAP[incomingKey]);
90+
Keyboard.press(KEY_MAP[incomingKey]);
91+
} else {
92+
Serial.print("O ");
93+
Serial.println(KEY_MAP[incomingKey]);
94+
Keyboard.release(KEY_MAP[incomingKey]);
95+
}
96+
9197
STATE_MAP[incomingKey] = incoming;
9298
}
9399

94100
void loop() {
95-
char output[12] = {'\0'};
96-
stateCheck(KEY_A, output);
97-
stateCheck(KEY_B, output);
98-
stateCheck(KEY_C, output);
99-
stateCheck(KEY_D, output);
100-
stateCheck(KEY_E, output);
101-
stateCheck(KEY_F, output);
102-
103-
Serial.println(output);
101+
stateCheck(KEY_A);
102+
stateCheck(KEY_B);
103+
stateCheck(KEY_C);
104+
stateCheck(KEY_D);
105+
stateCheck(KEY_E);
106+
stateCheck(KEY_F);
104107
delay(TAP_MS);
105-
106-
// Keyboard.print("You pressed the button ");
107-
// Keyboard.print(counter);
108-
// Keyboard.println(" times.");
109108
}

0 commit comments

Comments
 (0)