Zolovick_Larrea_Mouaffek / Mbed 2 deprecated ES202_Final_Project

Dependencies:   ContinuousServo TCS3472_I2C Tach mbed

Files at this revision

API Documentation at this revision

Comitter:
PlayaLarrea
Date:
Mon Apr 30 20:12:02 2018 +0000
Parent:
0:389040618ce2
Commit message:
FINAL CODE. STAYED IN BOUNDS, SENSED MINE AND FINISHED IN 29 SECONDS

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon Apr 30 17:16:55 2018 +0000
+++ b/main.cpp	Mon Apr 30 20:12:02 2018 +0000
@@ -1,3 +1,5 @@
+//ES202 FINAL PROJECT: LARREA, MOUAFFAK
+
 #include "mbed.h"
 #include "ContinuousServo.h"
 #include "Tach.h"
@@ -9,9 +11,8 @@
 PwmOut LB(p22); // PWM out signal to power LED on the sensor
 TCS3472_I2C rgb_sensor( p9, p10 ); // Establish RGB sensor object
 DigitalOut hallpwr(p22);
-DigitalIn hall(p21);
-BusOut flash(LED1, LED2, LED3, LED4);
-Ticker mine;
+InterruptIn hall(p21);
+DigitalOut flash(LED4);
 Ticker ultra;
 Serial pc(USBTX,USBRX);
 
@@ -21,34 +22,30 @@
 
 int rgb_data[4]; // declare a 4 element array to store RGB sensor readings
 float PWMbrightness = 1.0; // float specifying brightness of LED (between 0.0 and 1.0)
-int x;
+int x = 0;
 float a,b,c;
 
 void update()
 {
     a = 2.3*156.25*sonar.read();
-    //pc.printf("%f\r\n", a);
     wait(0.01);
     b = 2.3*156.25*sonar.read();
-    //pc.printf("%f\r\n", b);
     wait(0.01);
     c = 2.3*156.25*sonar.read();
-    //pc.printf("%f\r\n", c);
     wait(0.01);
     wall = (a+b+c)/3.0;
-    pc.printf("%f\r\n", wall);
 }
 
 void sweep()
 {
-    if(hall.read() == 1){
-        flash = 8.0;
-        wait(0.1);
-        hallpwr = 0;
-        }
-        else{
-            flash = 0.0;
-            }
+    x = x+1;
+    hallpwr = 0;
+    wait(0.2);
+    hallpwr = 1;
+    flash = 1;
+    wait(0.5);
+    flash = 0;
+    
 }
     
 int main()
@@ -57,7 +54,7 @@
 
     hall.mode(PullUp);
     hallpwr = 1;
-    mine.attach(&sweep, 0.1);
+    hall.rise(&sweep);
     
     rgb_sensor.enablePowerAndRGBC(); // Enable RGB sensor
     rgb_sensor.setIntegrationTime(100); // Set integration time of sensor
@@ -65,30 +62,21 @@
     wait(3);
 
     while(wall>=6.9) { // main code for driving goes here
-        //x = hall.read();
-        //if(x == 1) {
-        //    flash = 8.0;
-        //    wait(0.25);
-        //    x = 0;
-        //} else if (x == 0){
-        //    flash = 0.0;
-        //}
-        //x = hall.read();
 
         LB = PWMbrightness; // set brightness of sensor LED
         rgb_sensor.getAllColors( rgb_data );
-        pc.printf("%d\r\n", rgb_data[1]);
-        left.speed(.15);
-        right.speed(-.25);
+//        pc.printf("%d\r\n", rgb_data[1]);
+        left.speed(.12);
+        right.speed(-.22);
         if(rgb_data[1]<900) {
-            left.speed(.1);
-            right.speed(-.25);
+            left.speed(.09);
+            right.speed(-.22);
         } else if(rgb_data[1]>1000) {
-            left.speed(.19);
-            right.speed(-.18);
+            left.speed(.16);
+            right.speed(-.15);
         } else{
-            left.speed(.15);
-            right.speed(-.25);
+            left.speed(.12);
+            right.speed(-.22);
         }
     }
     left.stop();