test TTL

Dependencies:   mbed TextLCD

Files at this revision

API Documentation at this revision

Comitter:
mehrnaz
Date:
Thu May 23 14:39:11 2019 +0000
Parent:
0:a13b440d4fd1
Commit message:
feno board

Changed in this revision

TextLCD.lib Show annotated file Show diff for this revision Revisions of this file
flow.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Thu May 23 14:39:11 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/simon/code/TextLCD/#308d188a2d3a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flow.h	Thu May 23 14:39:11 2019 +0000
@@ -0,0 +1,20 @@
+#include "mbed.h"
+
+AnalogIn flowadc(PC_4);
+
+float flowVal1;
+float flowVal2;
+float Pressure;
+float finalflow;
+
+float flow()
+{
+    while(1) {
+
+   flowVal1=3.3*flowadc; //Logic level 3.3
+          flowVal2 = 1.5*flowVal1; //5v
+          Pressure =(125*flowVal2)-62.5;
+          finalflow=(0.1989*sqrt(Pressure))+0.0284; //flow in litter per min
+          return finalflow;
+            }
+}
\ No newline at end of file
--- a/main.cpp	Thu May 23 08:09:19 2019 +0000
+++ b/main.cpp	Thu May 23 14:39:11 2019 +0000
@@ -1,15 +1,70 @@
 #include "mbed.h"
-AnalogIn ain(A3);
+#include "flow.h"
+#include "TextLCD.h"
+
 Serial ttl(PA_0, PA_1);
+PwmOut led(PB_6);
+TextLCD lcd(PC_8,PC_6,PB_15,PB_14,PB_13,PB_12, TextLCD::LCD16x2);
+
 
 int main()
 {  
 
+    flow();
     ttl.baud(9600);
-    float x=0;
+    
+    lcd.cls();
+    wait(0.001);
+    lcd.locate(3,0);
+    lcd.printf("|");
+    lcd.locate(4,0);
+    lcd.printf("|");
+    
     
     while(1) {
-        x=3.3*ain; //Logic level 3.3
-        ttl.printf("%f\n", x);
+     
+     lcd.locate(8,0);
+    lcd.printf("f: %f\n", finalflow);
+     
+        //ttl.printf("flow: %f\n", finalflow);
+        if (flow()<0.4)
+        {
+            lcd.locate(0,1);
+            lcd.printf("*     ");
+            led.write(0.00f);
+        }
+        if (flow()>=0.4 and flow()<1.5)
+        {
+            lcd.locate(0,1);
+            lcd.printf("**    ");
+            led.write(0.20f);
+        }
+        if (flow()>=1.5 and flow()<2.7)
+        {
+            lcd.locate(0,1);
+            lcd.printf("***   ");
+            led.write(0.40f);
+        }
+        if (flow()>=2.7 and flow()<3)
+        {
+            lcd.locate(0,1);
+            lcd.printf("****  ");
+            led.write(0.60f);
+        }
+        if (flow()>=3 and flow()<3.3)
+        {
+            lcd.locate(0,1);
+            lcd.printf("***** ");
+            led.write(0.80f);
+        }
+        if (flow()>=3.3)
+        {
+            lcd.locate(0,1);
+            lcd.printf("******");
+            led.write(1.00f);
+        }
+   // lcd.printf("%f\n", flow());
+    wait (0.2);
+                
     }
 }