1 // The source for the Android application can be found at the following link: https://github.com/Lauszus/ArduinoBlinkLED
2 // The code for the Android application is heavily based on this guide: http://allaboutee.com/2011/12/31/arduino-adk-board-blink-an-led-with-your-phone-code-and-explanation/ by Miguel
6 // CAUTION! WARNING! ATTENTION! VORSICHT! ADVARSEL! ¡CUIDADO! ВНИМАНИЕ!
8 // Pin 13 is occupied by the SCK pin on various Arduino boards,
9 // including Uno, Duemilanove, etc., so use a different pin for those boards.
11 // CAUTION! WARNING! ATTENTION! VORSICHT! ADVARSEL! ¡CUIDADO! ВНИМАНИЕ!
13 #if defined(LED_BUILTIN)
14 #define LED LED_BUILTIN // Use built in LED
16 #define LED 9 // Set to something here that makes sense for your board.
20 // Satisfy IDE, which only needs to see the include statment in the ino.
22 #include <spi4teensy3.h>
27 ADK adk(&Usb, "TKJElectronics", // Manufacturer Name
28 "ArduinoBlinkLED", // Model Name
29 "Example sketch for the USB Host Shield", // Description (user-visible string)
31 "http://www.tkjelectronics.dk/uploads/ArduinoBlinkLED.apk", // URL (web page to visit if no installed apps support the accessory)
32 "123456789"); // Serial Number (optional)
39 #if !defined(__MIPSEL__)
40 while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
42 if (Usb.Init() == -1) {
43 Serial.print("\r\nOSCOKIRQ failed to assert");
47 Serial.print("\r\nArduino Blink LED Started");
56 Serial.print(F("\r\nConnected to accessory"));
60 uint16_t len = sizeof(msg);
61 uint8_t rcode = adk.RcvData(&len, msg);
62 if (rcode && rcode != hrNAK) {
63 Serial.print(F("\r\nData rcv: "));
64 Serial.print(rcode, HEX);
66 Serial.print(F("\r\nData Packet: "));
68 digitalWrite(LED, msg[0] ? HIGH : LOW);
71 if (millis() - timer >= 1000) { // Send data every 1s
73 rcode = adk.SndData(sizeof(timer), (uint8_t*)&timer);
74 if (rcode && rcode != hrNAK) {
75 Serial.print(F("\r\nData send: "));
76 Serial.print(rcode, HEX);
77 } else if (rcode != hrNAK) {
78 Serial.print(F("\r\nTimer: "));
85 Serial.print(F("\r\nDisconnected from accessory"));
86 digitalWrite(LED, LOW);