proyectotecnicas
/
menu-interrupciones
el menu chanta! se maneja con los dos switch
main.cpp@0:32e8c042c7e5, 2015-11-30 (annotated)
- Committer:
- josedaparte
- Date:
- Mon Nov 30 14:00:18 2015 +0000
- Revision:
- 0:32e8c042c7e5
menu
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
josedaparte | 0:32e8c042c7e5 | 1 | #include "mbed.h" |
josedaparte | 0:32e8c042c7e5 | 2 | #include "AnalogIn.h" |
josedaparte | 0:32e8c042c7e5 | 3 | #include "TextLCD.h" |
josedaparte | 0:32e8c042c7e5 | 4 | |
josedaparte | 0:32e8c042c7e5 | 5 | Serial pc(USBTX, USBRX); |
josedaparte | 0:32e8c042c7e5 | 6 | AnalogIn externo(PTC2); |
josedaparte | 0:32e8c042c7e5 | 7 | AnalogIn interno(PTB3); |
josedaparte | 0:32e8c042c7e5 | 8 | InterruptIn sw1(SW1); |
josedaparte | 0:32e8c042c7e5 | 9 | InterruptIn sw3(SW3); |
josedaparte | 0:32e8c042c7e5 | 10 | DigitalIn llave(PTA1); |
josedaparte | 0:32e8c042c7e5 | 11 | |
josedaparte | 0:32e8c042c7e5 | 12 | |
josedaparte | 0:32e8c042c7e5 | 13 | TextLCD lcd(PTD3, PTA12, PTA4, PTA5, PTC8, PTC9, TextLCD::LCD16x2); |
josedaparte | 0:32e8c042c7e5 | 14 | |
josedaparte | 0:32e8c042c7e5 | 15 | int temp = 26; |
josedaparte | 0:32e8c042c7e5 | 16 | char tipo; |
josedaparte | 0:32e8c042c7e5 | 17 | int sel = 1; |
josedaparte | 0:32e8c042c7e5 | 18 | float casinterno; |
josedaparte | 0:32e8c042c7e5 | 19 | float casexterno; |
josedaparte | 0:32e8c042c7e5 | 20 | float tinterno; |
josedaparte | 0:32e8c042c7e5 | 21 | float texterno; |
josedaparte | 0:32e8c042c7e5 | 22 | char modo = 'M'; |
josedaparte | 0:32e8c042c7e5 | 23 | |
josedaparte | 0:32e8c042c7e5 | 24 | void menu (){ |
josedaparte | 0:32e8c042c7e5 | 25 | lcd.cls(); |
josedaparte | 0:32e8c042c7e5 | 26 | switch (sel){ |
josedaparte | 0:32e8c042c7e5 | 27 | case 1: |
josedaparte | 0:32e8c042c7e5 | 28 | lcd.locate(0,0); |
josedaparte | 0:32e8c042c7e5 | 29 | lcd.printf("auto"); |
josedaparte | 0:32e8c042c7e5 | 30 | lcd.locate(0,1); |
josedaparte | 0:32e8c042c7e5 | 31 | lcd.printf("%.0fC %.0fC %c ho:ra", texterno, tinterno, modo); |
josedaparte | 0:32e8c042c7e5 | 32 | sel = 2; |
josedaparte | 0:32e8c042c7e5 | 33 | break; |
josedaparte | 0:32e8c042c7e5 | 34 | case 2: |
josedaparte | 0:32e8c042c7e5 | 35 | lcd.locate(0,0); |
josedaparte | 0:32e8c042c7e5 | 36 | lcd.printf("manual"); |
josedaparte | 0:32e8c042c7e5 | 37 | lcd.locate(0,1); |
josedaparte | 0:32e8c042c7e5 | 38 | lcd.printf("%.0fC %.0fC %c ho:ra", texterno, tinterno, modo); |
josedaparte | 0:32e8c042c7e5 | 39 | sel = 3; |
josedaparte | 0:32e8c042c7e5 | 40 | break; |
josedaparte | 0:32e8c042c7e5 | 41 | case 3: |
josedaparte | 0:32e8c042c7e5 | 42 | lcd.locate(0,0); |
josedaparte | 0:32e8c042c7e5 | 43 | lcd.printf("reloj"); |
josedaparte | 0:32e8c042c7e5 | 44 | lcd.locate(0,1); |
josedaparte | 0:32e8c042c7e5 | 45 | lcd.printf("%.0fC %.0fC %c ho:ra", texterno, tinterno, modo); |
josedaparte | 0:32e8c042c7e5 | 46 | sel = 1; |
josedaparte | 0:32e8c042c7e5 | 47 | break; |
josedaparte | 0:32e8c042c7e5 | 48 | case 4: |
josedaparte | 0:32e8c042c7e5 | 49 | lcd.locate(0,0); |
josedaparte | 0:32e8c042c7e5 | 50 | lcd.printf("temperatura"); |
josedaparte | 0:32e8c042c7e5 | 51 | lcd.locate(0,1); |
josedaparte | 0:32e8c042c7e5 | 52 | lcd.printf("%.0fC %.0fC %c ho:ra", texterno, tinterno, modo); |
josedaparte | 0:32e8c042c7e5 | 53 | sel = 5; |
josedaparte | 0:32e8c042c7e5 | 54 | break; |
josedaparte | 0:32e8c042c7e5 | 55 | case 5: |
josedaparte | 0:32e8c042c7e5 | 56 | lcd.locate(0,0); |
josedaparte | 0:32e8c042c7e5 | 57 | lcd.printf("tipo banio"); |
josedaparte | 0:32e8c042c7e5 | 58 | lcd.locate(0,1); |
josedaparte | 0:32e8c042c7e5 | 59 | lcd.printf("%.0fC %.0fC %c ho:ra", texterno, tinterno, modo); |
josedaparte | 0:32e8c042c7e5 | 60 | sel = 6; |
josedaparte | 0:32e8c042c7e5 | 61 | break; |
josedaparte | 0:32e8c042c7e5 | 62 | case 6: |
josedaparte | 0:32e8c042c7e5 | 63 | lcd.locate(0,0); |
josedaparte | 0:32e8c042c7e5 | 64 | lcd.printf("horarios"); |
josedaparte | 0:32e8c042c7e5 | 65 | lcd.locate(0,1); |
josedaparte | 0:32e8c042c7e5 | 66 | lcd.printf("%.0fC %.0fC %c ho:ra", texterno, tinterno, modo); |
josedaparte | 0:32e8c042c7e5 | 67 | sel = 9; |
josedaparte | 0:32e8c042c7e5 | 68 | break; |
josedaparte | 0:32e8c042c7e5 | 69 | case 7: |
josedaparte | 0:32e8c042c7e5 | 70 | lcd.locate(0,0); |
josedaparte | 0:32e8c042c7e5 | 71 | lcd.printf("temperatura"); |
josedaparte | 0:32e8c042c7e5 | 72 | lcd.locate(0,1); |
josedaparte | 0:32e8c042c7e5 | 73 | lcd.printf("%.0fC %.0fC %c ho:ra", texterno, tinterno, modo); |
josedaparte | 0:32e8c042c7e5 | 74 | sel = 8; |
josedaparte | 0:32e8c042c7e5 | 75 | break; |
josedaparte | 0:32e8c042c7e5 | 76 | case 8: |
josedaparte | 0:32e8c042c7e5 | 77 | lcd.locate(0,0); |
josedaparte | 0:32e8c042c7e5 | 78 | lcd.printf("tipo banio"); |
josedaparte | 0:32e8c042c7e5 | 79 | lcd.locate(0,1); |
josedaparte | 0:32e8c042c7e5 | 80 | lcd.printf("%.0fC %.0fC %c ho:ra", texterno, tinterno, modo); |
josedaparte | 0:32e8c042c7e5 | 81 | sel = 10; |
josedaparte | 0:32e8c042c7e5 | 82 | break; |
josedaparte | 0:32e8c042c7e5 | 83 | case 9: |
josedaparte | 0:32e8c042c7e5 | 84 | lcd.locate(0,0); |
josedaparte | 0:32e8c042c7e5 | 85 | lcd.printf("salir"); |
josedaparte | 0:32e8c042c7e5 | 86 | lcd.locate(0,1); |
josedaparte | 0:32e8c042c7e5 | 87 | lcd.printf("%.0fC %.0fC %c ho:ra", texterno, tinterno, modo); |
josedaparte | 0:32e8c042c7e5 | 88 | sel = 4; |
josedaparte | 0:32e8c042c7e5 | 89 | break; |
josedaparte | 0:32e8c042c7e5 | 90 | case 10: |
josedaparte | 0:32e8c042c7e5 | 91 | lcd.locate(0,0); |
josedaparte | 0:32e8c042c7e5 | 92 | lcd.printf("salir"); |
josedaparte | 0:32e8c042c7e5 | 93 | lcd.locate(0,1); |
josedaparte | 0:32e8c042c7e5 | 94 | lcd.printf("%.0fC %.0fC %c ho:ra", texterno, tinterno, modo); |
josedaparte | 0:32e8c042c7e5 | 95 | sel = 7; |
josedaparte | 0:32e8c042c7e5 | 96 | break; |
josedaparte | 0:32e8c042c7e5 | 97 | } |
josedaparte | 0:32e8c042c7e5 | 98 | } |
josedaparte | 0:32e8c042c7e5 | 99 | |
josedaparte | 0:32e8c042c7e5 | 100 | void selec(){ |
josedaparte | 0:32e8c042c7e5 | 101 | switch (sel){ |
josedaparte | 0:32e8c042c7e5 | 102 | case 2: |
josedaparte | 0:32e8c042c7e5 | 103 | modo = 'A'; |
josedaparte | 0:32e8c042c7e5 | 104 | sel = 4; |
josedaparte | 0:32e8c042c7e5 | 105 | menu(); |
josedaparte | 0:32e8c042c7e5 | 106 | break; |
josedaparte | 0:32e8c042c7e5 | 107 | case 3: |
josedaparte | 0:32e8c042c7e5 | 108 | modo = 'M'; |
josedaparte | 0:32e8c042c7e5 | 109 | sel = 7; |
josedaparte | 0:32e8c042c7e5 | 110 | menu(); |
josedaparte | 0:32e8c042c7e5 | 111 | break; |
josedaparte | 0:32e8c042c7e5 | 112 | case 1: |
josedaparte | 0:32e8c042c7e5 | 113 | pc.printf("aca ingresaria la hora\r\n"); |
josedaparte | 0:32e8c042c7e5 | 114 | wait(1.5); |
josedaparte | 0:32e8c042c7e5 | 115 | break; |
josedaparte | 0:32e8c042c7e5 | 116 | case 5: |
josedaparte | 0:32e8c042c7e5 | 117 | pc.printf("aca ingresaria la temperatura\r\n"); |
josedaparte | 0:32e8c042c7e5 | 118 | wait(1.5); |
josedaparte | 0:32e8c042c7e5 | 119 | break; |
josedaparte | 0:32e8c042c7e5 | 120 | case 6: |
josedaparte | 0:32e8c042c7e5 | 121 | pc.printf("aca ingresaria el tipo de banio\r\n"); |
josedaparte | 0:32e8c042c7e5 | 122 | wait(1.5); |
josedaparte | 0:32e8c042c7e5 | 123 | break; |
josedaparte | 0:32e8c042c7e5 | 124 | case 4: |
josedaparte | 0:32e8c042c7e5 | 125 | sel = 1; |
josedaparte | 0:32e8c042c7e5 | 126 | menu(); //salida1 |
josedaparte | 0:32e8c042c7e5 | 127 | break; |
josedaparte | 0:32e8c042c7e5 | 128 | case 8: |
josedaparte | 0:32e8c042c7e5 | 129 | pc.printf("aca ingresaria la temperatura2\r\n"); |
josedaparte | 0:32e8c042c7e5 | 130 | wait(1.5); |
josedaparte | 0:32e8c042c7e5 | 131 | break; |
josedaparte | 0:32e8c042c7e5 | 132 | case 7: |
josedaparte | 0:32e8c042c7e5 | 133 | sel = 2; |
josedaparte | 0:32e8c042c7e5 | 134 | menu(); |
josedaparte | 0:32e8c042c7e5 | 135 | break; |
josedaparte | 0:32e8c042c7e5 | 136 | case 9: |
josedaparte | 0:32e8c042c7e5 | 137 | pc.printf("aca ingresaria el horario\r\n"); |
josedaparte | 0:32e8c042c7e5 | 138 | wait(1.5); |
josedaparte | 0:32e8c042c7e5 | 139 | break; |
josedaparte | 0:32e8c042c7e5 | 140 | case 10: |
josedaparte | 0:32e8c042c7e5 | 141 | pc.printf("aca ingresaria tipo banio\r\n"); |
josedaparte | 0:32e8c042c7e5 | 142 | wait(1.5); |
josedaparte | 0:32e8c042c7e5 | 143 | break; |
josedaparte | 0:32e8c042c7e5 | 144 | } |
josedaparte | 0:32e8c042c7e5 | 145 | |
josedaparte | 0:32e8c042c7e5 | 146 | } |
josedaparte | 0:32e8c042c7e5 | 147 | |
josedaparte | 0:32e8c042c7e5 | 148 | int main() { |
josedaparte | 0:32e8c042c7e5 | 149 | |
josedaparte | 0:32e8c042c7e5 | 150 | pc.baud(115200); |
josedaparte | 0:32e8c042c7e5 | 151 | |
josedaparte | 0:32e8c042c7e5 | 152 | int comp; |
josedaparte | 0:32e8c042c7e5 | 153 | |
josedaparte | 0:32e8c042c7e5 | 154 | while(1){ |
josedaparte | 0:32e8c042c7e5 | 155 | |
josedaparte | 0:32e8c042c7e5 | 156 | sw1.fall(&menu); |
josedaparte | 0:32e8c042c7e5 | 157 | sw3.fall(&selec); |
josedaparte | 0:32e8c042c7e5 | 158 | //convierte voltaje a temperatura |
josedaparte | 0:32e8c042c7e5 | 159 | casexterno = externo.read() * 3.3; |
josedaparte | 0:32e8c042c7e5 | 160 | texterno = (casexterno + 0.2) * 100 / 5; |
josedaparte | 0:32e8c042c7e5 | 161 | casinterno = interno.read() * 3.3; |
josedaparte | 0:32e8c042c7e5 | 162 | tinterno = (casinterno + 2) * 100 / 8; |
josedaparte | 0:32e8c042c7e5 | 163 | |
josedaparte | 0:32e8c042c7e5 | 164 | lcd.locate(0,1); |
josedaparte | 0:32e8c042c7e5 | 165 | lcd.printf("%.0fC %.0fC %c ho:ra", texterno, tinterno, modo); |
josedaparte | 0:32e8c042c7e5 | 166 | |
josedaparte | 0:32e8c042c7e5 | 167 | comp = tinterno; |
josedaparte | 0:32e8c042c7e5 | 168 | if(comp == temp) |
josedaparte | 0:32e8c042c7e5 | 169 | pc.printf("las temperaturas son iguales\n\r"); |
josedaparte | 0:32e8c042c7e5 | 170 | else |
josedaparte | 0:32e8c042c7e5 | 171 | pc.printf("temperaturas distintas\n\r"); |
josedaparte | 0:32e8c042c7e5 | 172 | wait(1); |
josedaparte | 0:32e8c042c7e5 | 173 | } |
josedaparte | 0:32e8c042c7e5 | 174 | } |