Skip to content

Instantly share code, notes, and snippets.

@bostrot
Created January 2, 2020 12:57
Show Gist options
  • Save bostrot/e9ed2455f6e20ca28305d97573aa0987 to your computer and use it in GitHub Desktop.
Save bostrot/e9ed2455f6e20ca28305d97573aa0987 to your computer and use it in GitHub Desktop.
Simple Arduino / Teensy macro keypad
int button[5];
bool curPressed[5];
bool pressedD = false;
bool pressedM = false;
void setup()
{
Serial.begin(38400);
}
void loop()
{
// set button array to analog pins
for (int i = 0; i < 5; i++) {
button[i] = analogRead(i);
}
// button 1 pressed
if (button[0] > 1000) {
// check holding
if (!curPressed[0]) {
curPressed[0] = true;
Keyboard.press(MODIFIERKEY_ALT);
Keyboard.press(KEY_L);
Keyboard.press(KEY_M);
Keyboard.release(MODIFIERKEY_ALT);
Keyboard.release(KEY_L);
Keyboard.release(KEY_M);
Serial.println("button 1");
}
} else {
curPressed[0] = false;
}
// button 2 pressed
if (button[1] > 1000) {
// check holding
if (!curPressed[1]) {
curPressed[1] = true;
if (!pressedD) {
pressedD = true;
Keyboard.press(KEY_W);
} else {
pressedD = false;
Keyboard.release(KEY_W);
}
Serial.println("button 2");
} else {
curPressed[1] = false;
}
}
// button 3 pressed
if (button[2] > 1000) {
// check holding
if (!curPressed[2]) {
curPressed[2] = true;
if (!pressedD) {
pressedM = true;
Mouse.set_buttons(1, 0, 0);
} else {
pressedM = false;
Mouse.set_buttons(0, 0, 0);
}
Serial.println("button 3");
} else {
curPressed[2] = false;
}
}
delay(250);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment