Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Arduino USB Keyboard HID demo
- * Volume+/Volume-/Mute keys
- */
- uint8_t buf[8] = {
- 0 }; /* Keyboard report buffer */
- #define PIN_B 0
- #define PIN_A 1
- #define PIN_RB 2
- #define PIN_LB 4
- #define PIN_Y 5
- #define PIN_X 6
- #define PIN_LEFT 8
- #define PIN_DOWN 9
- #define PIN_RIGHT 11
- #define PIN_UP 12
- int state = 1;
- void setup()
- {
- Serial.begin(9600);
- pinMode(PIN_B, INPUT);
- pinMode(PIN_A, INPUT);
- pinMode(PIN_RB, INPUT);
- pinMode(PIN_LB, INPUT);
- pinMode(PIN_Y, INPUT);
- pinMode(PIN_X, INPUT);
- pinMode(PIN_LEFT, INPUT);
- pinMode(PIN_DOWN, INPUT);
- pinMode(PIN_RIGHT, INPUT);
- pinMode(PIN_UP, INPUT);
- // enable internal pull-ups
- digitalWrite(PIN_B, 1);
- digitalWrite(PIN_A, 1);
- digitalWrite(PIN_RB, 1);
- digitalWrite(PIN_LB, 1);
- digitalWrite(PIN_Y, 1);
- digitalWrite(PIN_X, 1);
- digitalWrite(PIN_LEFT, 1);
- digitalWrite(PIN_DOWN, 1);
- digitalWrite(PIN_RIGHT, 1);
- digitalWrite(PIN_UP, 1);
- delay(200);
- }
- void loop()
- {
- state = digitalRead(PIN_B);
- if (state != 1) {
- buf[2] = 13; // Volume up key
- Serial.write(buf, 8); // Send keypress
- releaseKey();
- }
- state = digitalRead(PIN_A);
- if (state != 1) {
- buf[2] = 14; // Volume down key
- Serial.write(buf, 8); // Send keypress
- releaseKey();
- }
- state = digitalRead(PIN_RB);
- if (state != 1) {
- buf[2] = 15; // Mute key
- Serial.write(buf, 8); // Send keypress
- releaseKey();
- }
- state = digitalRead(PIN_LB);
- if (state != 1) {
- buf[2] = 18; // Volume up key
- Serial.write(buf, 8); // Send keypress
- releaseKey();
- }
- state = digitalRead(PIN_Y);
- if (state != 1) {
- buf[2] = 128; // Volume down key
- Serial.write(buf, 8); // Send keypress
- releaseKey();
- }
- state = digitalRead(PIN_X);
- if (state != 1) {
- buf[2] = 12; // Mute key
- Serial.write(buf, 8); // Send keypress
- releaseKey();
- }
- state = digitalRead(PIN_LEFT);
- if (state != 1) {
- buf[2] = 4; // Volume up key
- Serial.write(buf, 8); // Send keypress
- releaseKey();
- }
- state = digitalRead(PIN_DOWN);
- if (state != 1) {
- buf[2] = 22; // Volume down key
- Serial.write(buf, 8); // Send keypress
- releaseKey();
- }
- state = digitalRead(PIN_RIGHT);
- if (state != 1) {
- buf[2] = 7; // Mute key
- Serial.write(buf, 8); // Send keypress
- releaseKey();
- }
- state = digitalRead(PIN_UP);
- if (state != 1) {
- buf[2] = 26; // Volume up key
- Serial.write(buf, 8); // Send keypress
- releaseKey();
- }
- }
- void releaseKey()
- {
- buf[0] = 0;
- buf[2] = 0;
- Serial.write(buf, 8); // Release key
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement