para este ejemplo use la versión 1.6 de el IDE de arduino, como se ve en la imagen el cable OTG se conecta a la entrada de USB Nativo del DUE, en algunos casos la corriente que proporciona el USB no es suficiente, por lo que hay q usar una fuente de poder de 10v
#include "variant.h"
#include <stdio.h>
#include <adk.h>
// Accessory descriptor. It's how Arduino identifies itself to Android.
char applicationName[] = "HelloADKLED"; // the app on your phone
char accessoryName[] = "Arduino Due"; // your Arduino board
char companyName[] = "Arduino-er";
// Make up anything you want for these
char versionNumber[] = "0.1";
char serialNumber[] = "1";
char url[] = "https://sites.google.com/site/arduinosite/exercise/androidadkled/AndroidADKLED_0.1.apk";
USBHost Usb;
ADK adk(&Usb, companyName, applicationName, accessoryName,versionNumber,url,serialNumber);
// Pin 13 has an LED connected on most Arduino boards.
int led = 13;
void setup() {
Serial.begin(9600);
cpu_irq_enable();
pinMode(led, OUTPUT);
//Indicate start of program
digitalWrite(led, LOW);
delay(2000);
digitalWrite(led, HIGH);
for(int i = 0; i <= 2; i++){
digitalWrite(led, HIGH);
delay(250);
digitalWrite(led, LOW);
delay(250);
}
}
#define RCVSIZE 128
void loop() {
char helloworld[] = "Hello World!\r\n";
uint8_t buf[RCVSIZE];
uint32_t nbread = 0;
Usb.Task();
if (adk.isReady()){
adk.read(&nbread, RCVSIZE, buf);
if (nbread > 0){
adk.write(nbread, buf);
//Convert nbread to String
String s = "";
for (uint32_t i = 0; i < nbread; ++i) {
s += (char)buf[i];
}
if(s == "LEDON"){
digitalWrite(led, HIGH);
}else if(s == "LEDOFF"){
digitalWrite(led, LOW);
}
}
}
}
No hay comentarios:
Publicar un comentario