Below is the code I was using. As for the wiring, two LEDs from pins 4 and 5 to ground with a small resist on each. a voltage divider resist coming off 5v to a push button switch and going back to 19 and 20. (different pins on 2.0 and ++2.0).
Obviously parts were cut-n-pasted from the RawHID example.
Code:
#define ACK 0x10
#define B1 0x20
#define B2 0x30
#define BER 0x40
#define B1Pin 19
#define B2Pin 20
#define LED1 4
#define LED2 5
void setup() {
Serial.begin(9600);
Serial.println("RawHID Example");
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(B1Pin, INPUT);
pinMode(B2Pin, INPUT);
}
// RawHID packets are always 64 bytes
//elapsedMillis msUntilNextSend;
int tripped = 0;
int blink = 0;
byte buffer[64];
int n;
void loop() {
int n;
n = RawHID.recv(buffer, 0); // 0 timeout = do not wait
if (n > 0) {
// the computer sent a message.
// See what the command is....
Serial.print(F("Received packet, first byte: "));
Serial.println((int)buffer[0]);
switch((int)buffer[0]) {
case 0x10: // clear both LEDS
Serial.println("Clearing");
digitalWrite(LED1,0);
digitalWrite(LED2,0);
tripped = 0;
break;
case 0x20: // blink both LEDS
Serial.println("Blinking");
break;
case 0x30: // swap LEDS
Serial.println("Swap");
if (tripped == 1) {
tripped = 2;
digitalWrite(LED1,0);
digitalWrite(LED2,255);
}
if (tripped == 2) {
tripped = 1;
digitalWrite(LED2,0);
digitalWrite(LED1,255);
}
break;
default:
Serial.println("UNKNOWN COMMAND!");
break;
}
sendPacket(ACK);
}
if (!tripped && (digitalRead(B1Pin) == HIGH)) {
tripped=1;
sendPacket(B1);
digitalWrite(LED1,255);
}
if (!tripped && (digitalRead(B2Pin) == HIGH)) {
tripped=2;
sendPacket(B2);
digitalWrite(LED2,255);
}
}
void sendPacket(int command) {
byte buffer[64];
// first 2 bytes are a signature
buffer[0] = 0xAB;
buffer[1] = 0xCD;
buffer[2] = command;
// fill the rest with zeros
for (int i=3; i<64; i++) {
buffer[i] = 0;
}
// actually send the packet
n = RawHID.send(buffer, 100);
if (n > 0) {
Serial.println(F("Transmitted packet"));
} else {
Serial.println(F("Unable to transmit packet"));
}
}