Level 2 Project Range Device

Dependencies:   N5110 SDFileSystem SRF02 TMP102 mbed

Revision:
1:5b991c2302e1
Parent:
0:0b180348c7e4
Child:
2:329597081c06
--- a/main.cpp	Fri Mar 18 15:04:05 2016 +0000
+++ b/main.cpp	Tue Mar 22 20:00:59 2016 +0000
@@ -3,8 +3,8 @@
 EL15PJT
 Embedded System Project
 EL2645
- 
- 
+
+
  Have added the N5110 Libary and set up a a basic disply of the Range reading
  as well as added LED indictors to range
 */
@@ -36,9 +36,11 @@
 
 int distance;
 int length;
+int alert
 
 // setup serial port
 void init_serial();
+
 // set up board
 void init_K64F();
 
@@ -49,12 +51,16 @@
     lcd.init();
     init_serial();
     init_K64F();
+
+
     while(1) {
 
         // read sensor distance in cm and print over serial port
         int distance = srf02.getDistanceCm();
+
         //serial link reading of range
         pc.printf("Distance = %i Cm\n",distance);
+
         // short delay before next measurement
         wait(0.25);
 
@@ -66,42 +72,43 @@
         // need to refresh display after setting pixels
         lcd.refresh();
 
-//LED range indicator runn of the bus out
-        if (distance >= 150) {
-            output = 3;
-        }
-
-        else if (100 <= distance  < 150) {
-            output = 15;
-        }
-
-        else if (distance <= 100) {
-            output = 67;
-        }
-
-        else {
-            output = 0
-
+//Range Alert selection
+        if (distance <= 200) {
+            alert = 6;
+        } else if (150 <= distance  < 200) {
+            alert = 6;
+        } else if (100 <=distance < 150) {
+            alert = 5;
+        } else if (50 <= distance < 100) {
+            alert = 4;
+        } else if ( 10 <=distance < 150) {
+            alert = 3;
+        } else if (distance <10) {
+            alert = 2;
+        } else {
+            output = 1;
         }
     }
+
 }
 
+
 // Used to return a range readig thru a serial connection
-void init_serial()
-{
-    // set to highest baud - ensure terminal software matches
-    pc.baud(115200);
-}
+    void init_serial() {
+        // set to highest baud - ensure terminal software matches
+        pc.baud(115200);
+    }
+
+
 //Set up board switches and LEDS
-void init_K64F()
-{
+    void init_K64F() {
 //on-board LEDs are active-low, so set pin high to turn them off.
-    r_led = 1;
-    g_led = 1;
-    b_led = 1;
+        r_led = 1;
+        g_led = 1;
+        b_led = 1;
 
 // since the on-board switches have external pull-ups, we should disable the internal pull-down
 // resistors that are enabled by default using InterruptIn
-    sw2.mode(PullNone);
-    sw3.mode(PullNone);
-}
\ No newline at end of file
+        sw2.mode(PullNone);
+        sw3.mode(PullNone);
+    }
\ No newline at end of file