Created
July 6, 2020 12:29
-
-
Save jes/fe1aeb18457a06562516372684d1bd47 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Keyboard.h> | |
#define NKEYS 3 | |
unsigned long mintime = 20; // ms (debounce time) | |
int keypin[NKEYS] = {2,3,4}; | |
char letter[NKEYS] = {'j', 'e', 's'}; | |
int isdown[NKEYS]; | |
unsigned long lastchange[NKEYS]; | |
void setup() { | |
Keyboard.begin(); | |
for (int i = 0; i < NKEYS; i++) | |
pinMode(keypin[i], INPUT_PULLUP); | |
} | |
void loop() { | |
for (int i = 0; i < NKEYS; i++) { | |
int down = !digitalRead(keypin[i]); | |
if (down != isdown[i]) { | |
isdown[i] = down; | |
lastchange[i] = millis(); | |
} | |
if (millis() - lastchange[i] > mintime) { | |
if (isdown[i]) { | |
Keyboard.press(letter[i]); | |
} else { | |
Keyboard.release(letter[i]); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment