Permalink
Browse files

Arduino code

  • Loading branch information...
1 parent 7b3a4a5 commit 9bab7b272723cf87f2e18b197157a078a6de7e03 @HalfdanJ HalfdanJ committed Jul 8, 2011
Showing with 597 additions and 0 deletions.
  1. +58 −0 arduino/arduino.pde
  2. +31 −0 arduino/com.pde
  3. +13 −0 server/AndroidManifest.xml
  4. +49 −0 server/arduino.pde
  5. +416 −0 server/lib.pde
  6. +30 −0 server/server.pde
View
@@ -0,0 +1,58 @@
+#include <SPI.h>
+#include <Adb.h>
+
+int left = 0;
+int right = 0;
+int leftDir = 0;
+int rightDir = 0;
+
+void setup()
+{
+ pinMode(10,OUTPUT);
+ pinMode(12,OUTPUT);
+ pinMode(11,OUTPUT);
+ pinMode(13,OUTPUT);
+
+ comSetup();
+
+ Serial.begin(57600);
+
+}
+
+void comReceive(uint8_t * data){
+ left = data[0];
+ right = data[1];
+// Serial.println("recv");
+ leftDir = data[2];
+ rightDir = data[3];
+}
+
+
+void loop()
+{
+ comUpdate();
+
+ if(leftDir > 0){
+ digitalWrite(12,HIGH);
+ analogWrite(10,255-left);
+ }
+ else {
+ digitalWrite(12,LOW);
+ analogWrite(10,left);
+ }
+
+ if(rightDir > 0){
+ digitalWrite(13,HIGH);
+ analogWrite(11,255-right);
+ }
+ else {
+ digitalWrite(13,LOW);
+ analogWrite(11,right);
+ }
+ delay(10);
+}
+
+
+
+
+
View
@@ -0,0 +1,31 @@
+
+// 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.println("sd");
+ comReceive(data);
+ }
+}
+
+void comSetup(){
+ ADB::init();
+ connection = ADB::addConnection("tcp:4567", true, adbEventHandler);
+}
+
+void comUpdate(){
+ ADB::poll();
+}
+
View
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="">
+ <uses-sdk android:minSdkVersion="7"/>
+ <application android:debuggable="true" android:icon="@drawable/icon" android:label="">
+ <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>
View
@@ -0,0 +1,49 @@
+import java.io.IOException;
+
+private Server server;
+
+void setupArduino(){
+ 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 updateArduino(){
+ try
+ {
+ server.send(new byte[] {
+ (byte) ((((float)mouseX)/((float)width))*255.0f)
+ ,(byte) ((((float)mouseY)/((float)height))*255.0f)
+ ,(byte) (leftRev?100:0)
+ ,(byte) (rightRev?100:0)
+ }
+ );
+ }
+ catch (IOException e)
+ {
+ println("microbridgeproblem sending TCP message");
+ }
+}
Oops, something went wrong.

0 comments on commit 9bab7b2

Please sign in to comment.