final

Dependencies:   TextLCD mbed

Fork of general by proyectotecnicas

Revision:
10:b76b433db252
Parent:
9:364316a55827
Child:
11:260de040b9e1
--- a/main.cpp	Wed Dec 16 01:19:25 2015 +0000
+++ b/main.cpp	Fri Dec 18 18:02:20 2015 +0000
@@ -2,19 +2,22 @@
 #include "TextLCD.h"
 #include "AnalogIn.h"
 #include "Serial.h"
+#include <TimerEvent.h>
 
 //clases
-Timer t;
+Ticker timeout;
 Serial pc(USBTX, USBRX);
 TextLCD lcd(PTD3, PTA12, PTA4, PTA5, PTC8, PTC9, TextLCD::LCD16x2);
 
 //entradas
-DigitalIn key1(PTE31), key4(PTE17), key2(PTE19), key3(PTE18);
+DigitalIn key1(PTE31),key2(PTE19), key3(PTE18), key4(PTE17);
 InterruptIn Enable(PTA13);
 AnalogIn externo(PTC2),interno(PTB3), presionin(PTB2), pident(PTB1);
 AnalogOut vref(PTE30);
 PwmOut pwmsal(PTD2);
 DigitalOut evalvula(PTE1);
+DigitalOut led_red(LED_RED);
+DigitalOut led_green(LED_GREEN);
 
 //declaracion de variables
 char tipo, modo = 'M';
@@ -26,6 +29,21 @@
 void selec();
 void func();
 
+void attimeout()
+{
+    min++;
+    if (min == 60) {
+        min = 0;
+        hora++;
+    }
+    if (hora == 24) {
+        hora = 0;
+        min = 0;
+    }
+
+}
+
+
 void funpresion()                                              //funcion de vaciado llenado
 {
     caspresion = presionin.read() * 3.3;
@@ -126,26 +144,31 @@
 {
     if(vrefe <= 1 && vrefe >= 0) {
         vref.write(vrefe);
-         pc.printf("vrefe= %.4f de salida vref\n\r",vrefe);
+        pc.printf("vrefe= %.4f de salida vref\n\r",vrefe);
     }
     valorpid = pident.read() * 3.3;
-    if(valorpid >1){
+    if(valorpid > 1 && ev == 0) {
         pwmsal.write(1);
-        pc.printf("vrefe= %.4f del 1 if\n\r",vrefe);}
-    else if(valorpid <= 1 && valorpid >= 0.6) {
+        pc.printf("vrefe= %.4f del 1 if\n\r",vrefe);
+        led_green = 0;
+    } else if(valorpid <= 1 && valorpid >= 0.69 && ev == 0) {
         valorpwm = 2.5 * valorpid - 1.5;
         pc.printf("vrefe= %.4f del 2 if\n\r",vrefe);
         pwmsal.write(valorpwm);
-    } else{
+        led_green = 0;
+    } else if(valorpid <= 0.69) {
         pwmsal.write(0);
-        pc.printf("vrefe= %.4f del else\n\r",vrefe);}
-        pc.printf("valorpid=%.4f\n\r",valorpid);
+        pc.printf("vrefe= %.4f del else\n\r",vrefe);
+        led_green = 1;
+
+    }
+    pc.printf("valorpid=%.4f\n\r",valorpid);
 }
 
 //funcion de set de hora
 void sethora()
 {
-    if(i == 0) {                                                                //set de primer digito hora
+    if(i == 0) {                                                              //set de primer digito hora
         if(num > 2) {
             lcd.locate(0,0);
             lcd.printf("valor invalido");
@@ -226,6 +249,9 @@
 //lectura de teclado y navegacion por menu
 void func()
 {
+    led_red = 1;
+    wait(.2);
+    led_red = 0;
     B1 = key1.read();
     B2 = key2.read();
     B3 = key3.read();
@@ -243,13 +269,12 @@
         switch(set) {
             case 0:
                 break;
-            case 1:                                                  //seteo hora
+            case 1:                                                  //seteo hora  
                 sethora();
                 if(i == 4) {                                        //pasa la hora al reloj
                     hora = (hh1 * 10) + hh0;
                     min = (mm1 * 10) + mm0;
                     hh0 = hh1 = mm1 = mm0 = 0;
-                    t.start();
                     lcd.locate(0,0);
                     lcd.printf("reloj          ");
                     lcd.locate(0,1);
@@ -465,6 +490,8 @@
             menu();
             break;
         case 1:
+            lcd.locate(0,0);
+            lcd.printf("ingrese datos");
             set = 1;
             break;
         case 5:
@@ -504,26 +531,13 @@
 //programa principal
 int main()
 {
-    t.start();
+    timeout.attach(&attimeout, 60);
     pc.baud(115200);
     Enable.rise(&func);
 
     while(1) {
         modotemp();
-//reloj
-        seg = t.read();
-        if(seg == 60) {
-            seg=0;
-            t.reset();
-            min++;
-        }
-        if(min==60) {
-            min=0;
-            hora++;
-        }
-        if(hora==24) {
-            hora=0;
-        }
+
         imprimehora();
 
 //convierte voltaje a temperatura
@@ -534,8 +548,7 @@
 
         lcd.locate(0,1);
         lcd.printf("%.0fC %.0fC %c ", texterno, tinterno, modo);
+        funpresion();
         pwm();
-        funpresion();
-        wait(1);
     }           //fin wile
 }
\ No newline at end of file