-
-
Save rodolfo3/fca5a67190f8c45b047f to your computer and use it in GitHub Desktop.
Minimum code to Arduino USB Keyboard using v-usb (from http://rodolfo3.wordpress.com)
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
// for Atmega328P | |
#define USB_INTR_VECTOR INT0_vect | |
#include "UsbKeyboard.h" | |
// To use USB, the interruption Timer0 is disabled, | |
// breaking the default delay function from Arduino | |
// Replacing by a new one | |
void delayMs(unsigned int ms) { // Safe delay helper function | |
for (int i = 0; i < ms; i++) { | |
delayMicroseconds(1000); | |
} | |
} | |
void setup() { | |
// Disable timer0 since it can mess with the USB timing. Note that | |
// this means some functions such as delay() will no longer work. | |
TIMSK0&=!(1<<TOIE0); | |
// Clear interrupts while performing time-critical operations | |
cli(); | |
// Force re-enumeration so the host will detect us | |
usbDeviceDisconnect(); | |
delayMs(250); | |
usbDeviceConnect(); | |
// Set interrupts again | |
sei(); | |
} | |
void loop() { | |
UsbKeyboard.update(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment