From 0de2c0e48b1cef722e72bea449fd075d3d885e38 Mon Sep 17 00:00:00 2001 From: Kristian Lauszus Date: Sun, 17 Nov 2013 18:57:03 +0100 Subject: [PATCH] Arduino can now write data to the Android phone as well --- .../adk/ArduinoBlinkLED/ArduinoBlinkLED.ino | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino b/examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino index f26be384..bc0cb95a 100644 --- a/examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino +++ b/examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino @@ -12,6 +12,8 @@ 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 +uint32_t timer; + void setup() { Serial.begin(115200); while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection @@ -29,13 +31,26 @@ void loop() { uint8_t msg[1]; uint16_t len = sizeof(msg); uint8_t rcode = adk.RcvData(&len, msg); - if (rcode && rcode != hrNAK) - USBTRACE2("Data rcv. :", rcode); - else if (len > 0) { + if (rcode && rcode != hrNAK) { + Serial.print(F("\r\nData rcv: ")); + Serial.print(rcode, HEX); + } else if (len > 0) { Serial.print(F("\r\nData Packet: ")); Serial.print(msg[0]); digitalWrite(LED, msg[0] ? HIGH : LOW); } + + if (millis() - timer >= 1000) { // Send data every 1s + timer = millis(); + rcode = adk.SndData(sizeof(timer), (uint8_t*)&timer); + if (rcode && rcode != hrNAK) { + Serial.print(F("\r\nData send: ")); + Serial.print(rcode, HEX); + } else if (rcode != hrNAK) { + Serial.print(F("\r\nTimer: ")); + Serial.print(timer); + } + } } else digitalWrite(LED, LOW);