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 18:22:34 2018 +0000
Revision:
9:d9148b367fd9
Parent:
8:bd5509788843
Child:
10:1c4ab7bc50b7
menus indo

Who changed what in which revision?

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