IHM com 4 botões e todas as telas de pontos

Dependencies:   TextLCD mbed

Fork of Menu_IHM by Rodrigo Lino

Committer:
Lucarn
Date:
Wed May 09 22:05:03 2018 +0000
Revision:
10:1c4ab7bc50b7
Parent:
9:d9148b367fd9
Child:
11:0cc3113c9ca8
certo

Who changed what in which revision?

UserRevisionLine numberNew contents of line
digo1234 7:a550ec99045b 1
digo1234 7:a550ec99045b 2 #include "mbed.h"
digo1234 7:a550ec99045b 3 #include "TextLCD.h"
digo1234 7:a550ec99045b 4 #define apertado 0
digo1234 7:a550ec99045b 5 #define solto 1
Lucarn 10:1c4ab7bc50b7 6
Lucarn 10:1c4ab7bc50b7 7
Lucarn 8:bd5509788843 8 DigitalIn button1(D5);
Lucarn 8:bd5509788843 9 DigitalIn button2(D4);
Lucarn 8:bd5509788843 10 DigitalIn button3(D6);
Lucarn 8:bd5509788843 11 DigitalIn button4(D7);
Lucarn 10:1c4ab7bc50b7 12
digo1234 7:a550ec99045b 13 DigitalOut led(LED2);
digo1234 7:a550ec99045b 14
digo1234 7:a550ec99045b 15 // Host PC Communication channels
digo1234 7:a550ec99045b 16 Serial pc(USBTX, USBRX); // tx, rx
digo1234 7:a550ec99045b 17
digo1234 7:a550ec99045b 18 // I2C Communication
digo1234 7:a550ec99045b 19 I2C i2c_lcd(D14,D15); // SDA, SCL
Lucarn 10:1c4ab7bc50b7 20
Lucarn 10:1c4ab7bc50b7 21
digo1234 7:a550ec99045b 22 TextLCD_I2C lcd(&i2c_lcd, 0x7E, TextLCD::LCD20x4); // I2C exp: I2C bus, PCF8574 Slaveaddress, LCD Type
Lucarn 10:1c4ab7bc50b7 23
digo1234 7:a550ec99045b 24 int menu=0;
Lucarn 9:d9148b367fd9 25 float x=420.69, y=420.69, z=420.69;
digo1234 7:a550ec99045b 26
digo1234 7:a550ec99045b 27
digo1234 7:a550ec99045b 28 int main() {
Lucarn 10:1c4ab7bc50b7 29
Lucarn 8:bd5509788843 30 //button1.fall(&aumenta_menu);
Lucarn 8:bd5509788843 31 //button2.fall(&diminui_menu);
digo1234 7:a550ec99045b 32
digo1234 7:a550ec99045b 33 lcd.setBacklight(TextLCD::LightOn);
digo1234 7:a550ec99045b 34 lcd.setCursor(TextLCD::CurOff_BlkOff);
digo1234 7:a550ec99045b 35
digo1234 7:a550ec99045b 36 while(1){
digo1234 7:a550ec99045b 37
Lucarn 8:bd5509788843 38 if (menu<0){
Lucarn 8:bd5509788843 39 menu=0;
Lucarn 8:bd5509788843 40 printf("menu %d \r\n",menu);
Lucarn 8:bd5509788843 41 }
Lucarn 8:bd5509788843 42 if (menu>6){
Lucarn 8:bd5509788843 43 menu=6;
Lucarn 8:bd5509788843 44 printf("menu %d \r\n",menu);
Lucarn 8:bd5509788843 45 }
Lucarn 8:bd5509788843 46
Lucarn 8:bd5509788843 47 while ((menu==0)&& (button1==solto) && (button2==solto) && (button3==solto) && (button4==solto)){
Lucarn 8:bd5509788843 48 lcd.setAddress(3,0);
Lucarn 8:bd5509788843 49 lcd.printf("MENU PRINCIPAL");
digo1234 7:a550ec99045b 50 lcd.setAddress(0,2);
digo1234 7:a550ec99045b 51 lcd.printf("1-SALVAR PONTOS");
digo1234 7:a550ec99045b 52 lcd.setAddress(0,3);
Lucarn 8:bd5509788843 53 lcd.printf("2-INICIAR PROGRAMA");
Lucarn 8:bd5509788843 54 if(button1==apertado)
Lucarn 8:bd5509788843 55 {menu+=1;}
Lucarn 8:bd5509788843 56 if(button2==apertado)
Lucarn 8:bd5509788843 57 {menu-=1;}
Lucarn 8:bd5509788843 58 /* if(button3==apertado)
Lucarn 8:bd5509788843 59 {menu=0;}
Lucarn 8:bd5509788843 60 if(button4==apertado)
Lucarn 8:bd5509788843 61 {menu=0;}*/
digo1234 7:a550ec99045b 62 }
digo1234 7:a550ec99045b 63 lcd.cls();
Lucarn 8:bd5509788843 64 while ((menu==1)&& (button1==solto) && (button2==solto) && (button3==solto) && (button4==solto)){
Lucarn 8:bd5509788843 65 //lcd.setAddress(0,0);
Lucarn 8:bd5509788843 66 //lcd.printf("SELECIONE O PONTO 1"); // Ponto 1
digo1234 7:a550ec99045b 67 lcd.setCursor(TextLCD::CurOff_BlkOff);
Lucarn 9:d9148b367fd9 68 lcd.setAddress(0,0);
Lucarn 9:d9148b367fd9 69 lcd.printf("1-SALVAR PONTO 1");
Lucarn 8:bd5509788843 70 lcd.setAddress(0,1);
Lucarn 9:d9148b367fd9 71 lcd.printf("2-VOLTAR");
digo1234 7:a550ec99045b 72 lcd.setAddress(0,2);
Lucarn 9:d9148b367fd9 73 lcd.printf("3-CANCELAR ");
Lucarn 9:d9148b367fd9 74 lcd.setAddress(11,1);
Lucarn 9:d9148b367fd9 75 lcd.printf("X:%.2f",x);
Lucarn 9:d9148b367fd9 76 lcd.setAddress(11,2);
Lucarn 9:d9148b367fd9 77 lcd.printf("Y:%.2f",y);
Lucarn 9:d9148b367fd9 78 lcd.setAddress(11,3);
Lucarn 9:d9148b367fd9 79 lcd.printf("Z:%.2f",z);
Lucarn 8:bd5509788843 80 // previous1 = 1;
digo1234 7:a550ec99045b 81 printf("dentro do menu1\r\n");
Lucarn 8:bd5509788843 82 if(button1==apertado)
Lucarn 8:bd5509788843 83 {menu+=1;}
Lucarn 8:bd5509788843 84 if(button2==apertado)
Lucarn 8:bd5509788843 85 {menu-=1;}
Lucarn 8:bd5509788843 86 if(button3==apertado)
Lucarn 8:bd5509788843 87 {menu=0;}
Lucarn 8:bd5509788843 88 /* if(button4==apertado)
Lucarn 8:bd5509788843 89 {menu=1;}*/
Lucarn 8:bd5509788843 90 }
Lucarn 8:bd5509788843 91 lcd.cls();
Lucarn 8:bd5509788843 92 while ((menu==2)&& (button1==solto) && (button2==solto) && (button3==solto) && (button4==solto)){
Lucarn 8:bd5509788843 93 //lcd.setAddress(0,0);
Lucarn 8:bd5509788843 94 //lcd.printf("SELECIONE O PONTO 2"); // Ponto 2
Lucarn 9:d9148b367fd9 95 //x=x+0.42;
Lucarn 9:d9148b367fd9 96 //y=y+0.17;
Lucarn 9:d9148b367fd9 97 //z=z+0.21;
Lucarn 8:bd5509788843 98 lcd.setCursor(TextLCD::CurOff_BlkOff);
Lucarn 9:d9148b367fd9 99 lcd.setAddress(0,0);
Lucarn 9:d9148b367fd9 100 lcd.printf("1-SALVAR PONTO 2");
Lucarn 8:bd5509788843 101 lcd.setAddress(0,1);
Lucarn 9:d9148b367fd9 102 lcd.printf("2-VOLTAR");
Lucarn 8:bd5509788843 103 lcd.setAddress(0,2);
Lucarn 9:d9148b367fd9 104 lcd.printf("3-CANCELAR");
Lucarn 8:bd5509788843 105 lcd.setAddress(0,3);
Lucarn 9:d9148b367fd9 106 lcd.printf("4-CONCLUIR");
Lucarn 9:d9148b367fd9 107 lcd.setAddress(11,1);
Lucarn 9:d9148b367fd9 108 lcd.printf("X:%.2f",x);
Lucarn 9:d9148b367fd9 109 lcd.setAddress(11,2);
Lucarn 9:d9148b367fd9 110 lcd.printf("Y:%.2f",y);
Lucarn 9:d9148b367fd9 111 lcd.setAddress(11,3);
Lucarn 9:d9148b367fd9 112 lcd.printf("Z:%.2f",z);
Lucarn 8:bd5509788843 113 // previous1 = 1;
Lucarn 8:bd5509788843 114 printf("dentro do menu2\r\n");
Lucarn 8:bd5509788843 115 if(button1==apertado)
Lucarn 8:bd5509788843 116 {menu+=1;}
Lucarn 8:bd5509788843 117 if(button2==apertado)
Lucarn 8:bd5509788843 118 {menu-=1;}
Lucarn 8:bd5509788843 119 if(button3==apertado)
Lucarn 8:bd5509788843 120 {menu=1;}
Lucarn 10:1c4ab7bc50b7 121 if(button4==apertado)
Lucarn 10:1c4ab7bc50b7 122 {menu=6;}
digo1234 7:a550ec99045b 123 }
digo1234 7:a550ec99045b 124 lcd.cls();
Lucarn 8:bd5509788843 125 while ((menu==3)&& (button1==solto) && (button2==solto) && (button3==solto) && (button4==solto)){
Lucarn 8:bd5509788843 126 // lcd.setAddress(0,0);
Lucarn 8:bd5509788843 127 //lcd.printf("SELECIONE O PONTO 3"); // Ponto 3
Lucarn 9:d9148b367fd9 128 //x=x+0.42;
Lucarn 9:d9148b367fd9 129 //y=y+0.17;
Lucarn 9:d9148b367fd9 130 //z=z+0.21;
Lucarn 8:bd5509788843 131 lcd.setCursor(TextLCD::CurOff_BlkOff);
digo1234 7:a550ec99045b 132 lcd.setAddress(0,0);
Lucarn 8:bd5509788843 133 lcd.printf("1-SALVAR PONTO 3");
Lucarn 8:bd5509788843 134 lcd.setAddress(0,1);
Lucarn 9:d9148b367fd9 135 lcd.printf("2-VOLTAR");
digo1234 7:a550ec99045b 136 lcd.setAddress(0,2);
Lucarn 9:d9148b367fd9 137 lcd.printf("3-CANCELAR");
digo1234 7:a550ec99045b 138 lcd.setAddress(0,3);
Lucarn 8:bd5509788843 139 lcd.printf("4-CONCLUIR");
Lucarn 9:d9148b367fd9 140 lcd.setAddress(11,1);
Lucarn 9:d9148b367fd9 141 lcd.printf("X:%.2f",x);
Lucarn 9:d9148b367fd9 142 lcd.setAddress(11,2);
Lucarn 9:d9148b367fd9 143 lcd.printf("Y:%.2f",y);
Lucarn 9:d9148b367fd9 144 lcd.setAddress(11,3);
Lucarn 9:d9148b367fd9 145 lcd.printf("Z:%.2f",z);
Lucarn 8:bd5509788843 146 //previous1 = 1;
Lucarn 8:bd5509788843 147 printf("dentro do menu3\r\n");
Lucarn 8:bd5509788843 148 if(button1==apertado)
Lucarn 8:bd5509788843 149 {menu+=1;}
Lucarn 8:bd5509788843 150 if(button2==apertado)
Lucarn 8:bd5509788843 151 {menu-=1;}
Lucarn 8:bd5509788843 152 if(button3==apertado)
Lucarn 8:bd5509788843 153 {menu=0;}
Lucarn 8:bd5509788843 154 if(button4==apertado)
Lucarn 8:bd5509788843 155 {menu=6;}
digo1234 7:a550ec99045b 156 }
digo1234 7:a550ec99045b 157 lcd.cls();
Lucarn 8:bd5509788843 158 while ((menu==4)&& (button1==solto) && (button2==solto) && (button3==solto) && (button4==solto)){
Lucarn 8:bd5509788843 159 // lcd.setAddress(0,0);
Lucarn 8:bd5509788843 160 //lcd.printf("SELECIONE O PONTO 3"); // Ponto 3
Lucarn 8:bd5509788843 161 lcd.setCursor(TextLCD::CurOff_BlkOff);
Lucarn 8:bd5509788843 162 lcd.setAddress(0,0);
Lucarn 9:d9148b367fd9 163 lcd.printf("1-SALVAR 4");
Lucarn 8:bd5509788843 164 lcd.setAddress(0,1);
Lucarn 9:d9148b367fd9 165 lcd.printf("2-VOLTAR");
Lucarn 8:bd5509788843 166 lcd.setAddress(0,2);
Lucarn 9:d9148b367fd9 167 lcd.printf("3-CANCELAR");
Lucarn 8:bd5509788843 168 lcd.setAddress(0,3);
Lucarn 8:bd5509788843 169 lcd.printf("4-CONCLUIR");
Lucarn 9:d9148b367fd9 170 lcd.setAddress(11,1);
Lucarn 9:d9148b367fd9 171 lcd.printf("X:%.2f",x);
Lucarn 9:d9148b367fd9 172 lcd.setAddress(11,2);
Lucarn 9:d9148b367fd9 173 lcd.printf("Y:%.2f",y);
Lucarn 9:d9148b367fd9 174 lcd.setAddress(11,3);
Lucarn 9:d9148b367fd9 175 lcd.printf("Z:%.2f",z);
Lucarn 8:bd5509788843 176 //previous1 = 1;
Lucarn 8:bd5509788843 177 printf("dentro do menu3\r\n");
Lucarn 8:bd5509788843 178 if(button1==apertado)
Lucarn 8:bd5509788843 179 {menu+=1;}
Lucarn 8:bd5509788843 180 if(button2==apertado)
Lucarn 8:bd5509788843 181 {menu-=1;}
Lucarn 8:bd5509788843 182 if(button3==apertado)
Lucarn 8:bd5509788843 183 {menu=0;}
Lucarn 8:bd5509788843 184 if(button4==apertado)
Lucarn 8:bd5509788843 185 {menu=6;}
Lucarn 8:bd5509788843 186 }
Lucarn 8:bd5509788843 187 lcd.cls();
Lucarn 8:bd5509788843 188 while ((menu==5)&& (button1==solto) && (button2==solto) && (button3==solto) && (button4==solto)){
Lucarn 8:bd5509788843 189 // lcd.setAddress(0,0);
Lucarn 8:bd5509788843 190 //lcd.printf("SELECIONE O PONTO 3"); // Ponto 3
Lucarn 8:bd5509788843 191 lcd.setCursor(TextLCD::CurOff_BlkOff);
Lucarn 8:bd5509788843 192 lcd.setAddress(0,0);
Lucarn 9:d9148b367fd9 193 lcd.printf("1-SALVAR 5");
Lucarn 8:bd5509788843 194 lcd.setAddress(0,1);
Lucarn 9:d9148b367fd9 195 lcd.printf("2-VOLTAR");
Lucarn 8:bd5509788843 196 lcd.setAddress(0,2);
Lucarn 9:d9148b367fd9 197 lcd.printf("3-CANCELAR");
Lucarn 8:bd5509788843 198 lcd.setAddress(0,3);
Lucarn 8:bd5509788843 199 lcd.printf("4-CONCLUIR");
Lucarn 9:d9148b367fd9 200 lcd.setAddress(11,1);
Lucarn 9:d9148b367fd9 201 lcd.printf("X:%.2f",x);
Lucarn 9:d9148b367fd9 202 lcd.setAddress(11,2);
Lucarn 9:d9148b367fd9 203 lcd.printf("Y:%.2f",y);
Lucarn 9:d9148b367fd9 204 lcd.setAddress(11,3);
Lucarn 9:d9148b367fd9 205 lcd.printf("Z:%.2f",z);
Lucarn 8:bd5509788843 206 //previous1 = 1;
Lucarn 8:bd5509788843 207 printf("dentro do menu3\r\n");
Lucarn 8:bd5509788843 208 if(button1==apertado)
Lucarn 8:bd5509788843 209 {menu+=1;}
Lucarn 8:bd5509788843 210 if(button2==apertado)
Lucarn 8:bd5509788843 211 {menu-=1;}
Lucarn 8:bd5509788843 212 if(button3==apertado)
Lucarn 8:bd5509788843 213 {menu=0;}
Lucarn 8:bd5509788843 214 if(button4==apertado)
Lucarn 8:bd5509788843 215 {menu=6;}
Lucarn 8:bd5509788843 216 }
Lucarn 8:bd5509788843 217 lcd.cls();
Lucarn 8:bd5509788843 218 while ((menu==6)&& (button1==solto) && (button2==solto) && (button3==solto) && (button4==solto)){
Lucarn 8:bd5509788843 219 lcd.setCursor(TextLCD::CurOff_BlkOff);
Lucarn 9:d9148b367fd9 220 lcd.setAddress(3,0);
Lucarn 9:d9148b367fd9 221 lcd.printf("PONTOS SALVOS!");
Lucarn 8:bd5509788843 222 lcd.setAddress(0,2);
Lucarn 9:d9148b367fd9 223 lcd.printf("1-VOLTAR AO MENU");
Lucarn 8:bd5509788843 224 lcd.setAddress(0,3);
Lucarn 9:d9148b367fd9 225 lcd.printf("2-RESSALVAR PONTOS");
Lucarn 8:bd5509788843 226 printf("dentro do menu4\r\n");
Lucarn 8:bd5509788843 227 if(button1==apertado)
Lucarn 8:bd5509788843 228 {menu=0;}
Lucarn 8:bd5509788843 229 if(button2==apertado)
Lucarn 8:bd5509788843 230 {menu=1;}
Lucarn 8:bd5509788843 231 }
Lucarn 8:bd5509788843 232 lcd.cls();
Lucarn 8:bd5509788843 233
digo1234 7:a550ec99045b 234 }
digo1234 7:a550ec99045b 235 }
Lucarn 10:1c4ab7bc50b7 236