First Draft, serial print change based on distance

Revision:
1:a1795335ef8c
Parent:
0:506531d0531c
Child:
2:3ace5b4ae9a7
diff -r 506531d0531c -r a1795335ef8c main.cpp
--- a/main.cpp	Sat Dec 04 17:15:09 2021 +0000
+++ b/main.cpp	Thu Dec 16 11:41:38 2021 +0000
@@ -2,49 +2,39 @@
 #include "ultrasonic.h"
 #include "N5110.h"
 
-// rows,cols
-int sprite[8][5] = {
-{ 0,0,1,0,0 },
-{ 0,1,1,1,0 },
-{ 0,0,1,0,0 },
-{ 0,1,1,1,0 },
-{ 1,1,1,1,1 },
-{ 1,1,1,1,1 },
-{ 1,1,0,1,1 },
-{ 1,1,0,1,1 },
-};
+ void dist(int distance)
+{
+    if (distance > 250){
+    printf("Safe Distance %dmm\r\n", distance);
+    }
+    else if (distance <= 250 and distance > 150){
+    printf("object detected %dmm\r\n", distance);
+    }
+    else if (distance <= 150 and distance > 80){
+    printf("object detected Closer %dmm\r\n", distance);
+    }
+    else if (distance <= 80 and distance > 60){
+    printf("Even Closer %dmm\r\n", distance);
+    }
+    else if (distance <= 60 and distance > 40){
+    printf("Very Very Close %dmm\r\n", distance);
+    }
+    else if (distance <= 40 and distance > 0){
+    printf("You've Hit a Wall %dmm\r\n", distance);
+    }
+}
 
-// VCC,SCE,RST,D/C,MOSI,SCLK,LED
-N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); //Set LCD Pins
-
-ultrasonic mu(PTA0, PTD0, .1, 1);    //Set the trigger pin to PTA0 and the echo pin to PTD0
+ultrasonic mu(PTD0, PTC12, .1, 1, &dist);    //Set the trigger pin to PTD0 and the echo pin to PTC12
                                         //have updates every .1 seconds and a timeout after 1
                                         //second, and call dist when the distance changes
 
 int main()
 {
-    // initialise lcd
-    lcd.init();
-    
-    // set lcd contrast
-    lcd.setContrast(0.4);
-    lcd.clear();
-    
     mu.startUpdates();//start mesuring the distance
     while(1)
     {
-        // x origin, y origin, rows, cols, sprite
-        lcd.drawSprite(20,6,8,5,(int *)sprite);
-        lcd.refresh();
-        wait(5.0);
-        
+        //Do something else here
         mu.checkDistance();     //call checkDistance() as much as possible, as this is where
                                 //the class checks if dist needs to be called.
-               
-        if (distance > 1000){ // check if somebody is infront of the sensor <--- needs resolving
-        lcd.clear(); // if nobody present then clear screen and turn backlight off
-        lcd.setBrightness(0.0);
-        printf("sleep"); // print sleep for debugging
-        }
     }
 }