Tank Control

Dependencies:   C12832_lcd mbed

Revision:
0:ae64d80e99a0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Jul 02 20:37:23 2013 +0000
@@ -0,0 +1,65 @@
+#include "mbed.h"
+#include "C12832_lcd.h"
+//#include "TextLCD.h"
+//TextLCD lcd(p5, p6, p7, p8, p9, p10); // rs, e, d7-d10
+C12832_LCD lcd;
+AnalogIn sonda(p19);
+DigitalOut B1(LED2);
+DigitalOut B2(LED4);
+Ticker bomba;
+int a=0;
+int x=2;
+float NS;
+float N;
+
+void Bom()
+{
+    if (a==0) {
+        a=1;
+    } else {
+        a=0;
+    }
+}
+int main()
+{
+    bomba.attach(&Bom, 5.0);
+    while(1) {
+        NS = sonda.read();
+        lcd.locate(0,0);
+        lcd.printf("nivel = %3.0f",NS*100);
+        if((((B1==1) && (B2==0)) || ((B1==0) && (B2==1))) && (NS >= 0.95)) {
+            x=2;
+        }
+        if((((B1==1) && (B2==0)) || ((B1==0) && (B2==1))) && (NS <= 0.45)) {
+            x=4;
+        }
+        if((B1==1) && (B2==1) &&( NS >= 0.55)) {
+            x=1;
+        }
+        if((B1==0) && (B2==0) && (NS <= 0.90)) {
+            x=3;
+        }
+        switch(x) {
+            case 2:
+                B1=0;
+                B2=0;
+                break;
+            case 4:
+                B1=1;
+                B2=1;
+                break;
+            default:        //Si x no es ni 2 ni 4 el programa al estado por defecto
+                if(a==1) {  //Mediante la función Ticker Bomba se realiza el control de 
+                    B1=1;   //la temporización de los 5 seg de funcionamiento intercalado de
+                    B2=0;   //la Bomba 1 y la 2.
+                } else {
+                    B1=0;
+                    B2=1;
+                }
+                break;
+        }
+    }
+}
+
+
+