Print when connected and disconnected from accessory

This commit is contained in:
Kristian Lauszus 2013-12-06 23:27:26 +01:00
parent 655b60ea90
commit 843eec8ba6

View file

@ -13,6 +13,7 @@ ADK adk(&Usb, "TKJElectronics", // Manufacturer Name
#define LED LED_BUILTIN // Use built in LED - note that pin 13 is occupied by the SCK pin on a normal Arduino (Uno, Duemilanove etc.), so use a different pin #define LED LED_BUILTIN // Use built in LED - note that pin 13 is occupied by the SCK pin on a normal Arduino (Uno, Duemilanove etc.), so use a different pin
uint32_t timer; uint32_t timer;
boolean connected;
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
@ -27,7 +28,13 @@ void setup() {
void loop() { void loop() {
Usb.Task(); Usb.Task();
if (adk.isReady()) { if (adk.isReady()) {
if (!connected) {
connected = true;
Serial.print(F("\r\nConnected to accessory"));
}
uint8_t msg[1]; uint8_t msg[1];
uint16_t len = sizeof(msg); uint16_t len = sizeof(msg);
uint8_t rcode = adk.RcvData(&len, msg); uint8_t rcode = adk.RcvData(&len, msg);
@ -51,7 +58,11 @@ void loop() {
Serial.print(timer); Serial.print(timer);
} }
} }
} } else {
else if (connected) {
connected = false;
Serial.print(F("\r\nDisconnected from accessory"));
digitalWrite(LED, LOW); digitalWrite(LED, LOW);
}
}
} }