Sebastian Sosa / Mbed 2 deprecated MbedProcessingCar

Dependencies:   mbed

Revision:
1:fc4305740d67
Child:
2:24f25fea5f95
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Processing.cpp	Wed Nov 12 00:09:41 2014 +0000
@@ -0,0 +1,117 @@
+//Processing code for a bluetooth controlled car that interfaces with processing in order to be controlled with an xbox360 controller
+//If further clarification is required contact @ sebastian.sosa@upaep.edu.mx
+//Library needs to be downloaded, also thanks to those guys, more info on the library on their page @ http://creativecomputing.cc/p5libs/procontroll/
+//Bluetooth is working being serial #1 if you have other serial devices conected modify as needed on line 35
+
+//PROCESSING CODE, COPY AND PASTE ON PROCESSING
+//Preferably on 32 bit version, even if your computer is 64bit
+
+import procontroll.*;
+import java.io.*;
+import processing.serial.*;
+
+Serial myPort;
+
+ControllIO controll;
+ControllDevice device;
+ControllSlider sliderX;
+ControllSlider sliderY;
+ControllButton button;
+ControllButton button2;
+
+void setup(){
+  size(400,400);
+  
+  controll = ControllIO.getInstance(this);
+
+  device = controll.getDevice("Controller (XBOX 360 For Windows)");
+  device.setTolerance(0.05f);
+  
+  sliderX = device.getSlider(1);
+  sliderY = device.getSlider(0);
+  button = device.getButton(0);
+  button2 = device.getButton(1);
+  
+  String portName = Serial.list()[1];
+  myPort = new Serial(this, portName, 9600);
+ 
+  
+  fill(0);
+  rectMode(CENTER);
+}
+
+void draw(){
+  background(255);
+  int vel = 0;
+  float rightM = 0;
+  float leftM = 0;
+  float right = 6;
+  float left = 6; 
+    while(true){
+        if(button.pressed()){
+      if(vel < 6){
+        vel = vel +1;
+      }    
+    }
+    if(button2.pressed()){
+      if(vel > -4){
+        vel = vel -1;
+      }
+    }
+    if(vel == 0){
+      rightM = 0;
+      leftM = 0;
+    }
+    if(button.pressed() == false && button2.pressed() == false && vel == 3){  // positivos
+      vel = vel -3;
+    }
+    if(button.pressed() == false && button2.pressed() == false && vel == 6){
+      vel = vel -3;
+    }
+    if(button.pressed() == false && button2.pressed() == false && vel == 2){
+      vel = vel -2;
+    }
+    if(button.pressed() == false && button2.pressed() == false && vel == 4){
+      vel = vel -2;
+    }
+    if(button.pressed() == false && button2.pressed() == false && vel == 1){
+      vel = vel -1;
+    }
+    if(button.pressed() == false && button2.pressed() == false && vel == 5){
+      vel = vel -3;
+    }
+    if(button.pressed() == false && button2.pressed() == false && vel== -1){  //negativos
+      vel = vel +1;
+    }
+    if(button.pressed() == false && button2.pressed() == false && vel== -2){  //negativos
+      vel = vel +2;
+    }
+    if(button.pressed() == false && button2.pressed() == false && vel== -3){  //negativos
+      vel = vel +3;
+    }
+    if(button.pressed() == false && button2.pressed() == false && vel== -4){  //negativos
+      vel = vel +2;
+    }
+    
+    else{
+      float y = sliderX.getValue()*5;
+      if(y>=0){
+        rightM = (right - y) * vel;
+        leftM = left * vel;
+      }
+      if(y<=0){
+        y = -y;
+        leftM = (left - y) * vel;
+        rightM = right * vel;
+      }
+    }
+    if(rightM <0){
+      rightM = (rightM * (-1)) + 60;
+      leftM = (leftM * (-1)) + 60;
+    }    
+    myPort.write(int(rightM));
+    myPort.write(int(leftM));
+    myPort.clear();
+    delay(200);
+  }
+}
\ No newline at end of file