Porn

Dependencies:   HCSR04 mbed

Fork of UltrasonicCasper by Casper Thomsen

Revision:
2:39179781a18c
Parent:
1:a8d4271903ac
Child:
3:bebb73b82a17
--- a/main.cpp	Mon May 26 14:12:13 2014 +0000
+++ b/main.cpp	Fri Apr 10 23:54:59 2015 +0000
@@ -1,41 +1,64 @@
 #include "mbed.h"
 #include "HCSR04.h"
 
+// Set's the Serial port
 Serial pc(USBTX, USBRX);
+
+// Defines the LED colors
 DigitalOut led(LED_RED);
 DigitalOut led2(LED_GREEN);
 
-HCSR04 sensor(PTA12, PTD4);
+// Defines the sensors (Left and Right)
+HCSR04 sensorLEFT(PTA12, PTD4);
+HCSR04 sensorRIGHT(PTA4, PTA5);
 
+// Get the left distance variable
+int distLeft(int dLEFT){
+    return dLEFT;    
+}
+
+// Get the right distance variable
+int distRight(int dRIGHT){
+    return dRIGHT;    
+}
+
+
+// The main() function
 int main()
 {
+    
+    // The loop() function
     while(1) {
-        int d = sensor.distance(CM);
+        //left and right distance variables 
+        int dLEFT = sensorLEFT.distance(CM);
+        int dRIGHT = sensorRIGHT.distance(CM);
         
-      
-       pc.printf("SENSOR %d \n\r\v",d);
-      
-       
- wait(0.2);
-        if(d<=10) {
+        // Writes the left and right distance variable
+       pc.printf("SENSOR Left: %d \n\r\v",distLeft(dLEFT));
+       pc.printf("SENSOR Right: %d \n\r\v",distRight(dRIGHT));
+        
+        // Delay
+        wait(0.5);
+        
+        //LED control
+        if(dRIGHT<=10) {
             led = 0;
             led2 = 1;
         }
 
-        if(d>=40) {
+        if(dRIGHT>=40) {
             led2 = 0;
             led = 1;
         }
-        if(d>=11 && d<=39) {
+        if(dRIGHT>=11 && dRIGHT<=39) {
             led2 = 0;
             led=0;
         }
-
-
-
     }
+    
 }
 
 
 
 
+