Skip to content

Instantly share code, notes, and snippets.

@windymelt
Last active October 8, 2018 14:24
Show Gist options
  • Save windymelt/c33131c252cce0b08227133a79cf9187 to your computer and use it in GitHub Desktop.
Save windymelt/c33131c252cce0b08227133a79cf9187 to your computer and use it in GitHub Desktop.
code for kinesis foot pedal.
#include <Keyboard.h>
#define LEFT_PAD PD0
#define MID_PAD PD1
#define RIGHT_PAD PD2
#define LEFT_LED PB0
#define MID_LED PB1
#define RIGHT_LED PB2
bool leftState = false;
bool midState = false;
bool rightState = false;
void setup() {
Serial.begin(9600);
Keyboard.begin();
pinMode(LEFT_PAD, INPUT_PULLUP);
pinMode(MID_PAD, INPUT_PULLUP);
pinMode(RIGHT_PAD, INPUT_PULLUP);
pinMode(LEFT_LED, OUTPUT);
pinMode(MID_LED, OUTPUT);
pinMode(RIGHT_LED, OUTPUT);
}
void operatePress(uint8_t key, bool* state, uint8_t keyCode, uint8_t led_pin) {
bool isPressed = digitalRead(key) == LOW;
if (isPressed && *state == false) {
Keyboard.press(keyCode);
digitalWrite(led_pin, HIGH);
*state = true;
} else if (!isPressed && *state == true) {
Keyboard.release(keyCode);
digitalWrite(led_pin, LOW);
*state = false;
}
}
void loop() {
operatePress(LEFT_PAD, &leftState, KEY_F13, LEFT_LED);
operatePress(MID_PAD, &midState, KEY_F14, MID_LED);
operatePress(RIGHT_PAD, &rightState, KEY_F15, RIGHT_LED);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment