USB 1key for Arduino Leonardo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // USB 1-key | |
| // 20140804 @houmei | |
| // | |
| #include <USBrawkeyboard.h> | |
| USBrawkeyboard rawkybd; | |
| #define BUTTON 4 | |
| #define LED 13 | |
| void setup() { | |
| pinMode(BUTTON,INPUT_PULLUP); | |
| pinMode(LED,OUTPUT); | |
| } | |
| int pressed; // BUTTON | |
| int prev; // previous pressed | |
| // int keycode=0x04; // 'a' | |
| // int keycode=0x46; // 'PRINT SCREEN' | |
| int keycode=0x35; // Zenkaku/Hankaku(JP Keyboard)/(~` US keyboard) | |
| // int keycode=0x89; // Yen -> need HID.cpp patch | |
| void loop() { | |
| pressed=!digitalRead(BUTTON); // 1..press 0..release | |
| if (pressed==prev) { | |
| digitalWrite(LED,pressed); | |
| if (pressed==1) { | |
| rawkybd.press(keycode); | |
| } else { | |
| rawkybd.release(keycode); | |
| } | |
| } | |
| prev=pressed; | |
| delay(50); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment