sdf

Dependencies:   mbed C12832 Servo RangeFinder Pulse

Revision:
1:47dc87d326ed
Parent:
0:4db5f0f5faa0
--- a/main.cpp	Wed Feb 23 10:19:24 2022 +0000
+++ b/main.cpp	Tue Mar 01 13:49:18 2022 +0000
@@ -3,6 +3,7 @@
 #include "RangeFinder.h"
 #include <Motor_relay.h>
 #include "Servo.h"
+#include <C12832.h>
 
 int dry = 0.61;
 int wet = 0.37;
@@ -13,7 +14,7 @@
 MOTOR_RELAY motor_relay2(p21);
 Servo valve1(p23);
 Servo valve2(p24);
-
+C12832 mylcd(p5,p7,p6,p8,p11);
 #define on  1
 #define off 0
 int main (void)
@@ -28,6 +29,9 @@
         moisturevalue = grove.read();
         moisturepercentage=(((moisturevalue- 0.37)/(0.61-0.37))*100);
         debug("Moisture reading is %2.2f percent dry\n\r",moisturepercentage);
+        mylcd.locate(0,0);
+        mylcd.printf("Moist: %.2f",moisturepercentage);
+
         wait(1.0f);
 
         d = rf.read_m();
@@ -39,28 +43,47 @@
             printf("No object within detection range.\n");
         } else  {
             printf("Distance = %f m.\n", d);
+            mylcd.locate(0,10);
+            mylcd.printf("Distance = %f m.\n", d);
         }
         wait(0.5);
         led = !led;
-        
-        
-        if(moisturepercentage>80){
+
+
+        if(moisturepercentage>80) {
+            mylcd.locate(0,10);
+            mylcd.printf("outletvalve:open pump:on");
             motor_relay1.SetMotor(1);
             valve1.position(0);
-            }
-        if(moisturepercentage<20){
+        }
+        if(moisturepercentage<20) {
+            mylcd.locate(0,10);
+            mylcd.printf("outletvalve:close pump:off");
             motor_relay1.SetMotor(0);
-              valve1.position(90);
-            }  
-       
+            valve1.position(90);
+        }
+        if(20<moisturepercentage<80) {
+            mylcd.locate(0,10);
+            mylcd.printf("Moisture:ok pump:off");
+            motor_relay1.SetMotor(0);
+        }
         if (d>0.07 ) {
+            mylcd.locate(0,20);
+            mylcd.printf("inletvalve:open pump:on");
             motor_relay2.SetMotor(1);
             valve2.position(90);
         }
         if(d<0.02) {
+            mylcd.locate(0,20);
+            mylcd.printf("inletvalve:closed pump:off");
             motor_relay2.SetMotor(0);
             valve2.position(0);
         }
+        if (0.02<d<0.07) {
+            mylcd.locate(0,20);
+            mylcd.printf("water level:ok pump:off");
+            motor_relay2.SetMotor(0);
+        }
     }
     return 0;
 }