#include #include #include #include "hid.h" // Modified HID library: doesn't prefix each packet with ID #include "instrument.h" //#include "blue.h" // Ginnie's blue guitar #include "standard.h" // Standard pins InstrumentButtonState buttonState; void setup() { pinMode(STRUM_DOWN, INPUT_PULLUP); pinMode(STRUM_UP, INPUT_PULLUP); pinMode(TILT_SWITCH, INPUT_PULLUP); pinMode(BUTTON_GREEN, INPUT_PULLUP); pinMode(BUTTON_RED, INPUT_PULLUP); pinMode(BUTTON_YELLOW, INPUT_PULLUP); pinMode(BUTTON_BLUE, INPUT_PULLUP); pinMode(BUTTON_ORANGE, INPUT_PULLUP); pinMode(SOLO_GREEN, INPUT_PULLUP); pinMode(SOLO_RED, INPUT_PULLUP); pinMode(SOLO_YELLOW, INPUT_PULLUP); pinMode(SOLO_BLUE, INPUT_PULLUP); pinMode(SOLO_ORANGE, INPUT_PULLUP); pinMode(ANALOG_WAMMY, INPUT); pinMode(BUTTON_PLUS, INPUT_PULLUP); pinMode(BUTTON_MINUS, INPUT_PULLUP); // Initialize HID static HIDSubDescriptor node(_hidReportDescriptor, sizeof(_hidReportDescriptor)); HID().AppendDescriptor(&node); buttonState.buttons = 0x0000; buttonState.hatAndConstant = 0x08; buttonState.axis[0] = 0; buttonState.axis[1] = 0; buttonState.axis[2] = 0; buttonState.axis[3] = 0; for (int i = 0; i < 12; i++) { buttonState.reserved1[i] = 0x0; } buttonState.finalConstant = 0x0200020002000200; buttonState.buttons = 0; buttonState.hatAndConstant = 0x08; // This apparently means "nothing pressed" } void loop() { static unsigned long next = 0; unsigned long now = millis(); // Send a state update right away; if (now >= next) { buttonState.axis[2] = analogRead(ANALOG_WAMMY) / 4; HID().SendReport(0, (uint8_t *)&buttonState, 27); buttonState.buttons = 0; // reset buttonState.hatAndConstant = 0x08; // reset next = now + 10; // wait 10ms before sending another status update } // Poll buttons if (!digitalRead(BUTTON_BLUE) || !digitalRead(SOLO_BLUE)) bitSet(buttonState.buttons, 0); if (!digitalRead(BUTTON_GREEN) || !digitalRead(SOLO_GREEN)) bitSet(buttonState.buttons, 1); if (!digitalRead(BUTTON_RED) || !digitalRead(SOLO_RED)) bitSet(buttonState.buttons, 2); if (!digitalRead(BUTTON_YELLOW) || !digitalRead(SOLO_YELLOW)) bitSet(buttonState.buttons, 3); if (!digitalRead(BUTTON_ORANGE) || !digitalRead(SOLO_ORANGE)) bitSet(buttonState.buttons, 4); if (!digitalRead(TILT_SWITCH)) bitSet(buttonState.buttons, 5); if (!digitalRead(SOLO_BLUE) || !digitalRead(SOLO_GREEN) || !digitalRead(SOLO_RED) || !digitalRead(SOLO_YELLOW) || !digitalRead(SOLO_ORANGE)) bitSet(buttonState.buttons, 6); if (!digitalRead(BUTTON_MINUS)) bitSet(buttonState.buttons, 8); if (!digitalRead(BUTTON_PLUS)) bitSet(buttonState.buttons, 9); // Poll direction // I don't understand why any rational engineer would have done this. if (!digitalRead(STRUM_UP)) { buttonState.hatAndConstant = 0x00; // up } else if (false) { buttonState.hatAndConstant = 0x02; // right } else if (!digitalRead(STRUM_DOWN)) { buttonState.hatAndConstant = 0x04; // down } else if (false) { buttonState.hatAndConstant = 0x06; // left } }