/* Basic Communication Example this is the easiest example to try out with the Arduino ADK board using the ADB communication scenario. It sends data from an analog sensor plugged on pin A0 to the phone and reads touches from the phone screen into the Arduino board execution analogWrite commands to pin D3 by Mads Hobye and Benjamin Weber from Illutron.dk and bw.nu */ #include #include #define MAX_RESET 8 // Adb connection. Connection * connection; // Elapsed time for ADC sampling long lastTime; boolean r = true; // Event handler for the shell connection. void adbEventHandler(Connection * connection, adb_eventType event, uint16_t length, uint8_t * data) { int i; // Data packets contain two bytes, one for each servo, in the range of [0..180] if (event == ADB_CONNECTION_RECEIVE) { r = !r; analogWrite(3,data[0]); Serial.print("analogWrite: "); Serial.println(data[0], DEC); } else if (event == ADB_CONNECT) { Serial.println("ADB_CONNECT"); } else if (event == ADB_DISCONNECT) { Serial.println("ADB_DISCONNECT"); } else if (event == ADB_CONNECTION_OPEN) { Serial.println("ADB_CONNECTION_OPEN"); } else if (event == ADB_CONNECTION_CLOSE) { Serial.println("ADB_CONNECTION_CLOSE"); } else if (event == ADB_CONNECTION_FAILED) { Serial.println("ADB_CONNECTION_FAILED"); } else { Serial.println("Undefined event"); } } void setup() { pinMode(3, OUTPUT); // Initialise serial port Serial.begin(57600); // Note start time lastTime = millis(); // Initialise the ADB subsystem. ADB::init(); // Open an ADB stream to the phone's shell. Auto-reconnect connection = ADB::addConnection("tcp:4567", true, adbEventHandler); } void loop() { if ((millis() - lastTime) > 20) { uint16_t data = analogRead(A0); connection->write(2, (uint8_t*)&data); lastTime = millis(); Serial.print("\t\t\t analogRead: "); Serial.println(data, DEC); } // Poll the ADB subsystem. ADB::poll(); }