First Draft, serial print change based on distance

Revision:
0:506531d0531c
Child:
1:a1795335ef8c
diff -r 000000000000 -r 506531d0531c main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Dec 04 17:15:09 2021 +0000
@@ -0,0 +1,50 @@
+#include "mbed.h"
+#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 },
+};
+
+// 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
+                                        //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);
+        
+        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
+        }
+    }
+}