From 20c49d2c11438bace354e4d98d8377939fb59777 Mon Sep 17 00:00:00 2001 From: di0ib Date: Tue, 30 May 2017 08:45:53 -1000 Subject: [PATCH] Add files via upload --- pico/2key.ino | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 pico/2key.ino diff --git a/pico/2key.ino b/pico/2key.ino new file mode 100644 index 0000000..dee402d --- /dev/null +++ b/pico/2key.ino @@ -0,0 +1,77 @@ +#include "HID-Project.h" + +//debounce milliseconds +const int debounce = 10; +//Switch Pins +const byte k[2] = { 2, 3 }; +//Switch status +boolean s[2] = { 0, 0 }; +//LED Pins +const byte l[2] = { 10, 9 }; + +//M for Media Key, K for Keyboard +const char codetype[6] = { 'K', 'K' }; + +//Keycodes +const ConsumerKeycode ccode[2] = { MEDIA_VOLUME_MUTE, + MEDIA_PLAY_PAUSE + }; + +const KeyboardKeycode kcode[2] = { KEY_UP_ARROW, + KEY_DOWN_ARROW + }; + +void setup() { + Keyboard.begin(); + Consumer.begin(); + + //setup inputs, turn on pullups + for (int i = 0; i <= 1; i++) { + pinMode(k[i], INPUT); + digitalWrite(k[i], 1); + pinMode(l[i], OUTPUT); + } +} + +void loop() { + CheckKeys(); + delay(debounce); +} + +void CheckKeys() { + for (int i = 0; i <= 1; i++) { + if (codetype[i] == 'M') { + if (digitalRead(k[i]) == 0) { + if (s[i] == 0) { + Consumer.press((ccode[i])); + s[i] = 1; + digitalWrite(l[i], 1); + } + } + else { + if (s[i] == 1) { + s[i] = 0; + digitalWrite(l[i], 0); + Consumer.release((ccode[i])); + } + } + } + if (codetype[i] == 'K') { + if (digitalRead(k[i]) == 0) { + if (s[i] == 0) { + Keyboard.press((kcode[i])); + s[i] = 1; + digitalWrite(l[i], 1); + } + } + else { + if (s[i] == 1) { + s[i] = 0; + digitalWrite(l[i], 0); + Keyboard.release((kcode[i])); + } + } + } + } +} +