Skip to content

Instantly share code, notes, and snippets.

@houmei
Created November 24, 2014 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save houmei/0ac6873618caa02f22b4 to your computer and use it in GitHub Desktop.
Save houmei/0ac6873618caa02f22b4 to your computer and use it in GitHub Desktop.
USB 1key for Arduino Leonardo
// 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