Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit f7d6e78c9ff69aa0d9a7f2f9a82ee837a244b003 @HalfdanJ HalfdanJ committed Jul 13, 2011
@@ -0,0 +1,63 @@
+#include <SPI.h>
+
+#include <Adb.h>
+#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]);
+ }
+
+
+}
+
+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);
+}
+int value = 0;
+void loop()
+{
+
+
+ if ((millis() - lastTime) > 20)
+ {
+ value = value + 1;
+ uint16_t data = 50;//analogRead(A0);
+ connection->write(2, (uint8_t*)&data);
+ lastTime = millis();
+ // Serial.println("sdf");
+ }
+
+ // Poll the ADB subsystem.
+ ADB::poll();
+}
+
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="" android:versionCode="1" android:versionName="1.0">
+ <uses-sdk android:minSdkVersion="7"/>
+ <application android:label="" android:icon="@drawable/icon" android:debuggable="true">
+ <activity android:name="">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ </activity>
+ </application>
+ <uses-permission android:name="android.permission.INTERNET"/>
+</manifest>
@@ -0,0 +1,67 @@
+import java.io.IOException;
+import android.util.Log;
+
+
+
+private Server server;
+private int sensorValue;
+
+void setup()
+{
+ orientation(PORTRAIT);
+ // Create TCP server
+ server = null;
+ try
+ {
+ server = new Server(4567);
+ server.start();
+ }
+ catch (IOException e)
+ {
+ println(e.toString());
+ }
+
+ this.server.addListener(new AbstractServerListener() {
+
+ @Override
+ public void onReceive(Client client, byte[] data)
+ {
+
+ if (data.length<2) return;
+
+ sensorValue = (data[0] & 0xff) | ((data[1] & 0xff) << 8);
+ };
+ }
+ );
+}
+
+void draw()
+{
+ background(200);
+
+ if (mousePressed)
+ {
+ fill(0, 255, 0);
+ ellipse(mouseX, height/2, 100,100);
+ try
+ {
+ server.send(new byte[] {
+ (byte) ((((float)mouseX)/((float)width))*255.0f)
+ ,(byte) ((((float)mouseY)/((float)height))*255.0f)
+ }
+ );
+
+ }
+ catch (IOException e)
+ {
+ println("microbridgeproblem sending TCP message");
+ }
+ }
+ else
+ {
+ fill(255, 0, 0);
+ ellipse(width/2, height/2, sensorValue, sensorValue);
+ }
+}
+
+
Oops, something went wrong.

0 comments on commit f7d6e78

Please sign in to comment.