Coursework

Revision:
1:757728321abd
Parent:
0:1f799c7cce2b
Child:
2:bb3dbda4d1f5
diff -r 1f799c7cce2b -r 757728321abd main.cpp
--- a/main.cpp	Thu Dec 16 14:03:11 2021 +0000
+++ b/main.cpp	Thu Dec 16 14:40:46 2021 +0000
@@ -5,7 +5,7 @@
 //                  y     x     button
 Joystick joystick(PTB10,PTB11,PTC16);
 HCSR04 sensor(D14, D15); 
-   long distance = sensor.distance(); 
+
 
 //      rows,cols
 int sprite[8][5] =   {
@@ -30,9 +30,20 @@
    lcd.setContrast(0.5);
     
     while(1) {
-    
+        long distanced = sensor.distance(); 
+        if (distanced >= 400 || distanced <= 2) 
+    {
+        printf("Out of range");
+        wait(1.0);
+    }
     
-   
+    else
+    
+    {
+      printf("Distance :  %d cm",distanced);
+      wait(1.0); // 1 sec  
+    }
+
         // these are default settings so not strictly needed
         lcd.normalMode();      // normal colour mode
         lcd.setBrightness(0.5); // put LED backlight on 50%
@@ -63,7 +74,7 @@
          printf(" *50 = %f,%f\n",x50,y50);
          // 
         // example of how to draw circles
-        lcd.printChar('o',x50/2,y50/2);
+        lcd.printChar('o',WIDTH/2,HEIGHT/2);
         lcd.refresh();
         
         
@@ -79,22 +90,7 @@
         }
 
    
-    if (distance >= 400 || distance <= 2) 
-    {
-        printf("Out of range");
-        wait(1.0);
-    }
-    if (distance >= 300 || distance <= 50)
-    {
-    printf("Range one");
-    wait(1.0);
-    }
-    else
-    
-    {
-      printf("Distance :  %d cm",distance);
-      wait(1.0); // 1 sec  
-    }
+
       
     }
 }