menu-teclado-lcd-pwm(funca todo) (y el puerto serie tambien)

Dependencies:   TextLCD mbed

Revision:
0:1334d6f26f42
Child:
1:9ab0f526b7a7
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Nov 30 15:54:23 2015 +0000
@@ -0,0 +1,196 @@
+#include "mbed.h"
+#include "TextLCD.h"
+#include "AnalogIn.h"
+
+Serial pc(USBTX, USBRX);
+TextLCD lcd(PTD3, PTA12, PTA4, PTA5, PTC8, PTC9, TextLCD::LCD16x2);
+
+DigitalIn key1(PTE31);
+DigitalIn key2(PTE19);
+DigitalIn key3(PTE18);
+DigitalIn key4(PTE17);
+InterruptIn Enable(PTA2);
+AnalogIn externo(PTC2);
+AnalogIn interno(PTB3);
+
+int temp = 26;
+char tipo;
+int sel = 1;
+float casinterno;
+float casexterno;
+float tinterno;
+float texterno;
+char modo = 'M';  
+
+int num, B1,B2,B3,B4;
+
+void menu();
+void selec();
+
+void func()
+{
+    pc.printf("entro a func\n\r");
+    B1 = key1.read();
+    B2 = key2.read();
+    B3 = key3.read();
+    B4 = key4.read();
+    
+    num = 2*2*2*B1 + 2*2*B2 + 2*B3 + B4;
+    
+    if(num == 10){
+        menu();
+                }else if(num == 11){
+                                    selec();
+                                            }}
+
+void menu (){
+    lcd.cls();
+    switch (sel){
+        case 1:                      
+            lcd.locate(0,0);
+            lcd.printf("auto");
+            lcd.locate(0,1);
+            lcd.printf("%.0fC %.0fC %c ho:ra", texterno, tinterno, modo);
+            sel = 2;
+            break;
+        case 2:
+            lcd.locate(0,0);
+            lcd.printf("manual");
+            lcd.locate(0,1);
+            lcd.printf("%.0fC %.0fC %c ho:ra", texterno, tinterno, modo);
+            sel = 3;
+            break;
+        case 3:            
+            lcd.locate(0,0);
+            lcd.printf("reloj");
+            lcd.locate(0,1);
+            lcd.printf("%.0fC %.0fC %c ho:ra", texterno, tinterno, modo);
+            sel = 1;
+            break;
+        case 4:           
+            lcd.locate(0,0);
+            lcd.printf("temperatura");
+            lcd.locate(0,1);
+            lcd.printf("%.0fC %.0fC %c ho:ra", texterno, tinterno, modo);
+            sel = 5;
+            break;
+        case 5:
+            lcd.locate(0,0);
+            lcd.printf("tipo banio");
+            lcd.locate(0,1);
+            lcd.printf("%.0fC %.0fC %c ho:ra", texterno, tinterno, modo);
+            sel = 6;
+            break;
+        case 6:            
+            lcd.locate(0,0);
+            lcd.printf("horarios");
+            lcd.locate(0,1);
+            lcd.printf("%.0fC %.0fC %c ho:ra", texterno, tinterno, modo);
+            sel = 9;
+            break;
+        case 7:            
+            lcd.locate(0,0);
+            lcd.printf("temperatura");
+            lcd.locate(0,1);
+            lcd.printf("%.0fC %.0fC %c ho:ra", texterno, tinterno, modo);
+            sel = 8;
+            break;
+        case 8:           
+            lcd.locate(0,0);
+            lcd.printf("tipo banio");
+            lcd.locate(0,1);
+            lcd.printf("%.0fC %.0fC %c ho:ra", texterno, tinterno, modo);
+            sel = 10;
+            break;
+        case 9:           
+            lcd.locate(0,0);
+            lcd.printf("salir");
+            lcd.locate(0,1);
+            lcd.printf("%.0fC %.0fC %c ho:ra", texterno, tinterno, modo);
+            sel = 4;
+            break;
+        case 10:
+            lcd.locate(0,0);
+            lcd.printf("salir");
+            lcd.locate(0,1);
+            lcd.printf("%.0fC %.0fC %c ho:ra", texterno, tinterno, modo);
+            sel = 7;
+            break;        
+            }       
+}
+
+
+void selec(){
+    switch (sel){
+        case 2:
+            modo = 'A';       
+            sel = 4;
+            menu();
+            break;
+        case 3:
+            modo = 'M';
+            sel = 7;
+            menu();
+            break;
+        case 1:
+            pc.printf("aca ingresaria la hora\r\n");
+            wait(1.5);
+            break;
+        case 5:
+            pc.printf("aca ingresaria la temperatura\r\n");
+            wait(1.5);
+            break;
+        case 6:
+            pc.printf("aca ingresaria el tipo de banio\r\n");
+            wait(1.5);
+            break;
+        case 4:
+            sel = 1;
+            menu();                    //salida1
+            break;
+        case 8:
+            pc.printf("aca ingresaria la temperatura2\r\n");
+            wait(1.5);
+            break;
+        case 7:
+            sel = 2;
+            menu();
+            break;
+        case 9:
+            pc.printf("aca ingresaria el horario\r\n");
+            wait(1.5);
+            break;
+        case 10:
+            pc.printf("aca ingresaria tipo banio\r\n");
+            wait(1.5);
+            break;
+            }
+    
+    }
+    
+        
+int main() {
+
+    Enable.rise(&func);
+    pc.baud(115200);
+    int comp;
+
+    while(1){
+
+//convierte voltaje a temperatura        
+        casexterno = externo.read() * 3.3;
+        texterno = (casexterno + 0.2) * 100 / 5;        
+        casinterno = interno.read() * 3.3;
+        tinterno = (casinterno + 2) * 100 / 8;
+        
+        lcd.locate(0,1);
+        lcd.printf("%.0fC %.0fC %c ho:ra", texterno, tinterno, modo);
+          
+        comp = tinterno;
+        if(comp == temp)
+            pc.printf("las temperaturas son iguales\n\r");
+        else
+            pc.printf("temperaturas distintas\n\r");
+            wait(1);
+    }
+}
\ No newline at end of file