Commit ab4f8d9f authored by Nicolas Lenz's avatar Nicolas Lenz
Browse files

Keyboard

parent e1a65209
/*
* Project 'Stream Cheap' Mini Macro Keyboard
* @author David Madison
* @link partsnotincluded.com/electronics/diy-stream-deck-mini-macro-keyboard
* @license MIT - Copyright (c) 2018 David Madison
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
#include "HID-Project.h"
const unsigned int debounceTime = 30;
// Button helper class for handling press/release and debouncing
class button {
public:
uint8_t key;
uint8_t pin;
button(uint8_t k, uint8_t p) : key(k), pin(p){}
void press(boolean state){
if(state == pressed || (millis() - lastPressed <= debounceTime)){
return; // Nothing to see here, folks
}
lastPressed = millis();
state ? Keyboard.press(KeyboardKeycode(key)) : Keyboard.release(KeyboardKeycode(key));
pressed = state;
}
void update(){
press(!digitalRead(pin));
}
private:
unsigned long lastPressed = 0;
boolean pressed = 0;
};
// Button objects, organized in array
button buttons[] = {
{KEY_F13, 2},
{KEY_F14, 3},
{KEY_F15, 4},
{KEY_F16, 5},
{KEY_F17, 6},
{KEY_F18, 7},
{KEY_F20, 8},
{KEY_F21, 9},
};
const uint8_t NumButtons = sizeof(buttons) / sizeof(button);
const uint8_t ledPin = 17;
void setup() {
Serial.begin(9600);
Keyboard.begin();
for(int i = 0; i < NumButtons; i++){
pinMode(buttons[i].pin, INPUT_PULLUP);
}
}
void loop() {
for(int i = 0; i < NumButtons; i++){
buttons[i].update();
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment