123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- #include <HID-Project.h>
- #include <HID-Settings.h>
-
- //number of keys
- const int keys = 12;
- //debounce milliseconds
- const int debounce = 5;
- //Switch Pins
- const byte k[12] = { 5, 6, 7, 8, 21, 20, 19, 18, 15, 14, 16, 10 };
- //Switch status
- boolean s[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
-
- //M for Media Key, K for Keyboard
- const char codetype[12] = { 'K', 'K', 'K', 'K', 'K', 'K', 'K', 'K', 'K', 'K', 'K', 'K' };
-
- //Keycodes
- const ConsumerKeycode ccode[keys] = { MEDIA_VOLUME_MUTE,
- MEDIA_VOLUME_MUTE,
- MEDIA_PLAY_PAUSE,
- MEDIA_PLAY_PAUSE,
- MEDIA_PLAY_PAUSE,
- MEDIA_PLAY_PAUSE,
- MEDIA_PLAY_PAUSE,
- MEDIA_PLAY_PAUSE,
- MEDIA_PLAY_PAUSE,
- MEDIA_PLAY_PAUSE,
- MEDIA_PLAY_PAUSE,
- MEDIA_PLAY_PAUSE
- };
-
- const KeyboardKeycode kcode[keys] = { KEY_F1,
- KEY_F2,
- KEY_F3,
- KEY_F4,
- KEY_F5,
- KEY_F6,
- KEY_F7,
- KEY_F8,
- KEY_F9,
- KEY_F10,
- KEY_F11,
- KEY_F12
- };
-
- void setup() {
- Keyboard.begin();
- Consumer.begin();
- //setup inputs, turn on pullups
- for (int i = 0; i < keys; i++) {
- pinMode(k[i], INPUT);
- digitalWrite(k[i], 1);
- }
- }
-
- void loop() {
- CheckKeys();
- delay(debounce);
- }
-
- void CheckKeys() {
- for (int i = 0; i < keys; i++) {
- if (codetype[i] == 'M') {
- if (digitalRead(k[i]) == 0) {
- if (s[i] == 0) {
- Consumer.press((ccode[i]));
- s[i] = 1;
- }
- }
- else {
- if (s[i] == 1) {
- s[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;
- }
- }
- else {
- if (s[i] == 1) {
- s[i] = 0;
- Keyboard.release((kcode[i]));
- }
- }
- }
- }
- }
-
-
|