mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Merge pull request #9 from TKJElectronics/master
Added ArduinoBlinkLED ADK Example
This commit is contained in:
commit
235a869016
1 changed files with 46 additions and 0 deletions
46
examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino
Normal file
46
examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
// The source for the Android application can be found at the following link: http://www.tkjelectronics.dk/uploads/ArduinoBlinkLED.zip
|
||||||
|
// 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
|
||||||
|
|
||||||
|
#include <Usb.h>
|
||||||
|
#include <adk.h>
|
||||||
|
|
||||||
|
USB Usb;
|
||||||
|
ADK adk(&Usb,"TKJElectronics", // Manufacturer Name
|
||||||
|
"ArduinoBlinkLED", // Model Name
|
||||||
|
"Example sketch for the USB Host Shield", // Description (user-visible string)
|
||||||
|
"1.0", // Version
|
||||||
|
"http://www.tkjelectronics.dk/uploads/ArduinoBlinkLED.apk", // URL (web page to visit if no installed apps support the accessory)
|
||||||
|
"123456789"); // Serial Number (optional)
|
||||||
|
|
||||||
|
#define LED_RED 13 // Pin 13 is occupied by the SCK pin on a normal Arduino (Uno, Duemilanove etc.), so use a different pin
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
Serial.begin(115200);
|
||||||
|
Serial.print("\r\nADK demo start");
|
||||||
|
if (Usb.Init() == -1) {
|
||||||
|
Serial.print("\r\nOSCOKIRQ failed to assert");
|
||||||
|
while(1); //halt
|
||||||
|
}
|
||||||
|
pinMode(LED_RED, OUTPUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
Usb.Task();
|
||||||
|
if(adk.isReady()) {
|
||||||
|
uint8_t msg[1];
|
||||||
|
uint16_t len = sizeof(msg);
|
||||||
|
uint8_t rcode = adk.RcvData(&len, msg);
|
||||||
|
if(rcode && rcode != hrNAK)
|
||||||
|
USBTRACE2("Data rcv. :", rcode);
|
||||||
|
if(len > 0) {
|
||||||
|
Serial.print(F("\r\nData Packet: "));
|
||||||
|
Serial.print(msg[0]);
|
||||||
|
digitalWrite(LED_RED,msg[0] ? HIGH : LOW);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
digitalWrite(LED_RED, LOW);
|
||||||
|
delay(10);
|
||||||
|
}
|
Loading…
Reference in a new issue