Código para o menu no LCD
Dependencies: mbed SDFileSystemSD TextLCD
Fork of TextLCD_HelloWorld2 by
main.cpp@10:97002056ecda, 2018-05-11 (annotated)
- Committer:
- claraluques
- Date:
- Fri May 11 12:46:56 2018 +0000
- Revision:
- 10:97002056ecda
- Parent:
- 9:86b5a317fcd4
- Child:
- 11:6b7accf18fe2
tava tudo ok, bot?o meio sensivel. Tentar implementar as coordenadas variando e/ou criar telas de automatico e config.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wim | 0:a75049de1a82 | 1 | #include "mbed.h" |
wim | 0:a75049de1a82 | 2 | #include "TextLCD.h" |
claraluques | 5:30f5ffe0ea0b | 3 | /* |
claraluques | 5:30f5ffe0ea0b | 4 | // Host PC Communication channels |
claraluques | 5:30f5ffe0ea0b | 5 | Serial pc(USBTX, USBRX); // tx, rx |
wim | 4:a3e4bb2053cb | 6 | |
claraluques | 5:30f5ffe0ea0b | 7 | //I2C Communication |
claraluques | 5:30f5ffe0ea0b | 8 | I2C i2c_lcd(D14,D15); // SDA, SCL |
claraluques | 5:30f5ffe0ea0b | 9 | |
claraluques | 5:30f5ffe0ea0b | 10 | //Botão push |
claraluques | 5:30f5ffe0ea0b | 11 | InterruptIn botao(D7); |
claraluques | 5:30f5ffe0ea0b | 12 | |
claraluques | 5:30f5ffe0ea0b | 13 | //LCD instantiation |
claraluques | 5:30f5ffe0ea0b | 14 | TextLCD_I2C lcd(&i2c_lcd, 0x7E, TextLCD::LCD20x4); // I2C exp: I2C bus, PCF8574 Slaveaddress, LCD Type |
claraluques | 5:30f5ffe0ea0b | 15 | |
claraluques | 5:30f5ffe0ea0b | 16 | //variáveis int |
claraluques | 5:30f5ffe0ea0b | 17 | int colunas = lcd.columns(); |
claraluques | 5:30f5ffe0ea0b | 18 | int linhas = lcd.rows(); |
claraluques | 5:30f5ffe0ea0b | 19 | int c1 = 510000000; |
claraluques | 5:30f5ffe0ea0b | 20 | int pontosl = 10; |
claraluques | 5:30f5ffe0ea0b | 21 | int botpres; |
claraluques | 5:30f5ffe0ea0b | 22 | |
claraluques | 5:30f5ffe0ea0b | 23 | //variáveis float |
claraluques | 5:30f5ffe0ea0b | 24 | float coordx = 123; |
claraluques | 5:30f5ffe0ea0b | 25 | float coardy = 456; |
claraluques | 5:30f5ffe0ea0b | 26 | float coardz = 789; |
claraluques | 5:30f5ffe0ea0b | 27 | |
claraluques | 5:30f5ffe0ea0b | 28 | //funções |
claraluques | 5:30f5ffe0ea0b | 29 | void botao_press(void); |
claraluques | 5:30f5ffe0ea0b | 30 | void botao_solto(void); |
claraluques | 5:30f5ffe0ea0b | 31 | |
claraluques | 5:30f5ffe0ea0b | 32 | int main() { |
claraluques | 5:30f5ffe0ea0b | 33 | lcd.setBacklight(TextLCD::LightOn); //liga backlight |
claraluques | 5:30f5ffe0ea0b | 34 | lcd.cls(); |
claraluques | 5:30f5ffe0ea0b | 35 | lcd.printf("Certifique-se de que voce esta seguro para comecar"); |
claraluques | 5:30f5ffe0ea0b | 36 | |
claraluques | 5:30f5ffe0ea0b | 37 | botao.rise(&botao_press); |
claraluques | 5:30f5ffe0ea0b | 38 | botao.fall(&botao_solto); |
claraluques | 5:30f5ffe0ea0b | 39 | wait(2); |
claraluques | 5:30f5ffe0ea0b | 40 | |
claraluques | 5:30f5ffe0ea0b | 41 | while(1){ |
claraluques | 5:30f5ffe0ea0b | 42 | while(1) { |
claraluques | 5:30f5ffe0ea0b | 43 | |
claraluques | 5:30f5ffe0ea0b | 44 | |
claraluques | 5:30f5ffe0ea0b | 45 | if (c1>500000000) { |
claraluques | 5:30f5ffe0ea0b | 46 | lcd.cls(); |
claraluques | 5:30f5ffe0ea0b | 47 | lcd.printf("FUNCAO JOG"); |
claraluques | 5:30f5ffe0ea0b | 48 | lcd.locate(0,1); |
claraluques | 5:30f5ffe0ea0b | 49 | //lcd.printf("X: %.1f Y: %d.1 Z: %d.1", coordx, coordy, coordz); |
claraluques | 5:30f5ffe0ea0b | 50 | lcd.locate(0,2); |
claraluques | 5:30f5ffe0ea0b | 51 | lcd.printf("Aperte > ok p/ salvar o ponto %c", 0x3E); |
claraluques | 5:30f5ffe0ea0b | 52 | //wait(0.5) |
claraluques | 5:30f5ffe0ea0b | 53 | //lcd.printf("Aperte ok p/ salvar o ponto %c", 0xff); |
claraluques | 5:30f5ffe0ea0b | 54 | InterruptIn botao(D7); |
claraluques | 5:30f5ffe0ea0b | 55 | c1 = 0; |
claraluques | 5:30f5ffe0ea0b | 56 | } |
claraluques | 5:30f5ffe0ea0b | 57 | |
claraluques | 5:30f5ffe0ea0b | 58 | c1++; |
claraluques | 5:30f5ffe0ea0b | 59 | |
claraluques | 5:30f5ffe0ea0b | 60 | if(botpres) { //se pressionado, aparece a tela de ponto salvo com contagem de pontos restantes |
claraluques | 5:30f5ffe0ea0b | 61 | lcd.cls(); |
claraluques | 5:30f5ffe0ea0b | 62 | lcd.locate(0,0); |
claraluques | 5:30f5ffe0ea0b | 63 | lcd.printf("Voce salvou um ponto"); |
claraluques | 5:30f5ffe0ea0b | 64 | lcd.locate(0,2); |
claraluques | 5:30f5ffe0ea0b | 65 | pontosl--; |
claraluques | 5:30f5ffe0ea0b | 66 | lcd.printf("Pontos livres: %d",pontosl); |
claraluques | 5:30f5ffe0ea0b | 67 | wait(2); |
claraluques | 5:30f5ffe0ea0b | 68 | c1=510000000; |
claraluques | 5:30f5ffe0ea0b | 69 | break; |
claraluques | 5:30f5ffe0ea0b | 70 | } |
claraluques | 5:30f5ffe0ea0b | 71 | } |
claraluques | 5:30f5ffe0ea0b | 72 | } |
claraluques | 5:30f5ffe0ea0b | 73 | } |
claraluques | 5:30f5ffe0ea0b | 74 | |
claraluques | 5:30f5ffe0ea0b | 75 | void botao_press(void){ |
claraluques | 5:30f5ffe0ea0b | 76 | botpres = 1; |
claraluques | 5:30f5ffe0ea0b | 77 | printf("pressionado\n\r"); |
claraluques | 5:30f5ffe0ea0b | 78 | } |
claraluques | 5:30f5ffe0ea0b | 79 | void botao_solto(void) { |
claraluques | 5:30f5ffe0ea0b | 80 | botpres = 0; |
claraluques | 5:30f5ffe0ea0b | 81 | printf("solto\n\r"); |
claraluques | 5:30f5ffe0ea0b | 82 | } |
claraluques | 5:30f5ffe0ea0b | 83 | */ |
claraluques | 5:30f5ffe0ea0b | 84 | |
claraluques | 5:30f5ffe0ea0b | 85 | //#include mbed.h |
claraluques | 5:30f5ffe0ea0b | 86 | //#include "TextLCD.h" |
claraluques | 5:30f5ffe0ea0b | 87 | |
wim | 0:a75049de1a82 | 88 | // Host PC Communication channels |
wim | 0:a75049de1a82 | 89 | Serial pc(USBTX, USBRX); // tx, rx |
wim | 4:a3e4bb2053cb | 90 | |
claraluques | 5:30f5ffe0ea0b | 91 | //I2C Communication |
claraluques | 5:30f5ffe0ea0b | 92 | I2C i2c_lcd(D14,D15); // SDA, SCL |
claraluques | 5:30f5ffe0ea0b | 93 | |
claraluques | 5:30f5ffe0ea0b | 94 | //Botão push |
claraluques | 5:30f5ffe0ea0b | 95 | InterruptIn botao_enter(D13); |
claraluques | 5:30f5ffe0ea0b | 96 | InterruptIn botao_cima(D10); |
claraluques | 5:30f5ffe0ea0b | 97 | InterruptIn botao_baixo(D9); |
claraluques | 5:30f5ffe0ea0b | 98 | |
claraluques | 5:30f5ffe0ea0b | 99 | //LCD instantiation |
claraluques | 5:30f5ffe0ea0b | 100 | TextLCD_I2C lcd(&i2c_lcd, 0x7E, TextLCD::LCD20x4); // I2C exp: I2C bus, PCF8574 Slaveaddress, LCD Type |
claraluques | 5:30f5ffe0ea0b | 101 | |
claraluques | 5:30f5ffe0ea0b | 102 | //variáveis int |
claraluques | 5:30f5ffe0ea0b | 103 | //int max = 3; |
claraluques | 5:30f5ffe0ea0b | 104 | //int min = 0; |
claraluques | 5:30f5ffe0ea0b | 105 | int bot_enter; |
claraluques | 5:30f5ffe0ea0b | 106 | int bot_cima; |
claraluques | 5:30f5ffe0ea0b | 107 | int bot_baixo; |
claraluques | 6:24cbbdf2dac2 | 108 | int penter = 0; |
claraluques | 6:24cbbdf2dac2 | 109 | int pcima = 0; |
claraluques | 6:24cbbdf2dac2 | 110 | int pbaixo = 0; |
claraluques | 9:86b5a317fcd4 | 111 | int cola; |
claraluques | 9:86b5a317fcd4 | 112 | int exec; |
wim | 0:a75049de1a82 | 113 | |
claraluques | 5:30f5ffe0ea0b | 114 | //variáveis float |
claraluques | 7:e2c1b0338286 | 115 | float cx = 120.458; |
claraluques | 7:e2c1b0338286 | 116 | float cy = 457.854; |
claraluques | 7:e2c1b0338286 | 117 | float cz = 782.659; |
claraluques | 8:b80f50544ddd | 118 | float cx_salva; |
claraluques | 8:b80f50544ddd | 119 | float cy_salva; |
claraluques | 8:b80f50544ddd | 120 | float cz_salva; |
claraluques | 5:30f5ffe0ea0b | 121 | |
claraluques | 5:30f5ffe0ea0b | 122 | //funções interrupt |
claraluques | 5:30f5ffe0ea0b | 123 | void botenter_press(void); |
claraluques | 5:30f5ffe0ea0b | 124 | void botenter_solto(void); |
wim | 0:a75049de1a82 | 125 | |
claraluques | 5:30f5ffe0ea0b | 126 | void botcima_press(void); |
claraluques | 5:30f5ffe0ea0b | 127 | void botcima_solto(void); |
claraluques | 5:30f5ffe0ea0b | 128 | |
claraluques | 5:30f5ffe0ea0b | 129 | void botbaixo_press(void); |
claraluques | 5:30f5ffe0ea0b | 130 | void botbaixo_solto(void); |
claraluques | 5:30f5ffe0ea0b | 131 | |
claraluques | 5:30f5ffe0ea0b | 132 | //criar classe "menu" (funções das telas) |
claraluques | 5:30f5ffe0ea0b | 133 | class Menu{ |
claraluques | 5:30f5ffe0ea0b | 134 | public: |
claraluques | 5:30f5ffe0ea0b | 135 | int linha; |
claraluques | 7:e2c1b0338286 | 136 | //int coluna; |
claraluques | 5:30f5ffe0ea0b | 137 | int func; |
wim | 4:a3e4bb2053cb | 138 | |
claraluques | 6:24cbbdf2dac2 | 139 | void movercursor(int min, int max, int col){ //função para mover cursor de seleção |
claraluques | 5:30f5ffe0ea0b | 140 | linha = min; |
claraluques | 7:e2c1b0338286 | 141 | lcd.locate(col,min); |
claraluques | 7:e2c1b0338286 | 142 | lcd.printf("%c", 0x3E); |
claraluques | 6:24cbbdf2dac2 | 143 | while (bot_enter==penter){ |
claraluques | 5:30f5ffe0ea0b | 144 | if (bot_cima==1){ |
claraluques | 5:30f5ffe0ea0b | 145 | if (linha==min){ |
claraluques | 6:24cbbdf2dac2 | 146 | lcd.locate(col,min); |
claraluques | 6:24cbbdf2dac2 | 147 | lcd.printf(" "); |
claraluques | 5:30f5ffe0ea0b | 148 | linha=max; |
claraluques | 6:24cbbdf2dac2 | 149 | lcd.locate(col, linha); |
claraluques | 6:24cbbdf2dac2 | 150 | lcd.printf("%c", 0x3E); |
claraluques | 5:30f5ffe0ea0b | 151 | } |
claraluques | 5:30f5ffe0ea0b | 152 | else { |
claraluques | 6:24cbbdf2dac2 | 153 | lcd.locate(col,linha); |
claraluques | 6:24cbbdf2dac2 | 154 | lcd.printf(" "); |
claraluques | 5:30f5ffe0ea0b | 155 | linha--; |
claraluques | 6:24cbbdf2dac2 | 156 | lcd.locate(col, linha); |
claraluques | 6:24cbbdf2dac2 | 157 | lcd.printf("%c", 0x3E); |
claraluques | 5:30f5ffe0ea0b | 158 | } |
claraluques | 6:24cbbdf2dac2 | 159 | bot_cima = 0; |
claraluques | 5:30f5ffe0ea0b | 160 | } |
claraluques | 5:30f5ffe0ea0b | 161 | if (bot_baixo==1){ |
claraluques | 5:30f5ffe0ea0b | 162 | if (linha==max){ |
claraluques | 6:24cbbdf2dac2 | 163 | lcd.locate(col,max); |
claraluques | 6:24cbbdf2dac2 | 164 | lcd.printf(" "); |
claraluques | 5:30f5ffe0ea0b | 165 | linha=min; |
claraluques | 6:24cbbdf2dac2 | 166 | lcd.locate(col, linha); |
claraluques | 6:24cbbdf2dac2 | 167 | lcd.printf("%c", 0x3E); |
claraluques | 5:30f5ffe0ea0b | 168 | } |
claraluques | 5:30f5ffe0ea0b | 169 | else { |
claraluques | 6:24cbbdf2dac2 | 170 | lcd.locate(col,linha); |
claraluques | 6:24cbbdf2dac2 | 171 | lcd.printf(" "); |
claraluques | 5:30f5ffe0ea0b | 172 | linha++; |
claraluques | 6:24cbbdf2dac2 | 173 | lcd.locate(col, linha); |
claraluques | 6:24cbbdf2dac2 | 174 | lcd.printf("%c", 0x3E); |
claraluques | 5:30f5ffe0ea0b | 175 | } |
claraluques | 6:24cbbdf2dac2 | 176 | bot_baixo = 0; |
claraluques | 5:30f5ffe0ea0b | 177 | } |
claraluques | 6:24cbbdf2dac2 | 178 | //lcd.locate(col, linha); |
claraluques | 6:24cbbdf2dac2 | 179 | //lcd.printf("%c", 0x3E); |
claraluques | 6:24cbbdf2dac2 | 180 | //printf("%d \n\r",linha); |
claraluques | 7:e2c1b0338286 | 181 | //printf("%d %d %d \n\r", bot_enter, bot_cima, bot_baixo); |
claraluques | 7:e2c1b0338286 | 182 | //wait_ms(500); |
claraluques | 5:30f5ffe0ea0b | 183 | } |
claraluques | 5:30f5ffe0ea0b | 184 | //printf("%d \n\r",linha); |
claraluques | 5:30f5ffe0ea0b | 185 | } |
claraluques | 5:30f5ffe0ea0b | 186 | |
claraluques | 5:30f5ffe0ea0b | 187 | |
claraluques | 5:30f5ffe0ea0b | 188 | //func 0 |
claraluques | 5:30f5ffe0ea0b | 189 | void inicializar(){ //função tela incial de boas-vindas |
claraluques | 5:30f5ffe0ea0b | 190 | lcd.cls(); |
claraluques | 8:b80f50544ddd | 191 | lcd.locate(4,0); |
claraluques | 8:b80f50544ddd | 192 | lcd.printf("Bem-vindo(a)"); |
claraluques | 5:30f5ffe0ea0b | 193 | lcd.locate(0,1); |
claraluques | 8:b80f50544ddd | 194 | lcd.printf("Utilize seu EPI para operar a maquina."); |
claraluques | 9:86b5a317fcd4 | 195 | wait(1); |
claraluques | 5:30f5ffe0ea0b | 196 | func = 1; |
claraluques | 5:30f5ffe0ea0b | 197 | } |
claraluques | 5:30f5ffe0ea0b | 198 | |
claraluques | 5:30f5ffe0ea0b | 199 | //func 1 |
claraluques | 5:30f5ffe0ea0b | 200 | void menuprincipal(){ //função menu principal |
claraluques | 9:86b5a317fcd4 | 201 | bot_enter = 0; |
claraluques | 5:30f5ffe0ea0b | 202 | lcd.cls(); |
claraluques | 5:30f5ffe0ea0b | 203 | lcd.locate(1,0); |
claraluques | 5:30f5ffe0ea0b | 204 | lcd.printf("Modo JOG"); |
claraluques | 5:30f5ffe0ea0b | 205 | lcd.locate(1,1); |
claraluques | 5:30f5ffe0ea0b | 206 | lcd.printf("Modo Automatico"); |
claraluques | 5:30f5ffe0ea0b | 207 | lcd.locate(1,2); |
claraluques | 5:30f5ffe0ea0b | 208 | lcd.printf("Config"); |
claraluques | 9:86b5a317fcd4 | 209 | lcd.locate(1,3); |
claraluques | 9:86b5a317fcd4 | 210 | lcd.printf("Zerar"); |
claraluques | 9:86b5a317fcd4 | 211 | movercursor(0,3,0); |
claraluques | 6:24cbbdf2dac2 | 212 | if (bot_enter!=penter){ |
claraluques | 5:30f5ffe0ea0b | 213 | if (linha==0){ |
claraluques | 5:30f5ffe0ea0b | 214 | func = 2; |
claraluques | 5:30f5ffe0ea0b | 215 | } |
claraluques | 5:30f5ffe0ea0b | 216 | else if (linha==1) { |
claraluques | 5:30f5ffe0ea0b | 217 | func = 3; |
claraluques | 5:30f5ffe0ea0b | 218 | } |
claraluques | 5:30f5ffe0ea0b | 219 | else if (linha==2) { |
claraluques | 5:30f5ffe0ea0b | 220 | func = 4; |
claraluques | 5:30f5ffe0ea0b | 221 | } |
claraluques | 9:86b5a317fcd4 | 222 | else if (linha==3) { |
claraluques | 9:86b5a317fcd4 | 223 | func = 8; |
claraluques | 9:86b5a317fcd4 | 224 | } |
claraluques | 5:30f5ffe0ea0b | 225 | } |
claraluques | 5:30f5ffe0ea0b | 226 | } |
claraluques | 6:24cbbdf2dac2 | 227 | |
claraluques | 6:24cbbdf2dac2 | 228 | |
claraluques | 6:24cbbdf2dac2 | 229 | //func 2 |
claraluques | 6:24cbbdf2dac2 | 230 | void jog(){ //função tela jog |
claraluques | 9:86b5a317fcd4 | 231 | bot_enter = 0; |
claraluques | 6:24cbbdf2dac2 | 232 | lcd.cls(); |
claraluques | 7:e2c1b0338286 | 233 | lcd.locate(4,0); |
claraluques | 7:e2c1b0338286 | 234 | lcd.printf("Coordenadas:"); |
claraluques | 7:e2c1b0338286 | 235 | lcd.locate(0,1); |
claraluques | 7:e2c1b0338286 | 236 | lcd.printf("X:%.3f", cx); |
claraluques | 7:e2c1b0338286 | 237 | lcd.locate(0,2); |
claraluques | 7:e2c1b0338286 | 238 | lcd.printf("Y:%.3f", cy); |
claraluques | 7:e2c1b0338286 | 239 | lcd.locate(0,3); |
claraluques | 7:e2c1b0338286 | 240 | lcd.printf("Z:%.3f", cz); |
claraluques | 6:24cbbdf2dac2 | 241 | lcd.locate(11,1); |
claraluques | 6:24cbbdf2dac2 | 242 | lcd.printf("Salvar"); |
claraluques | 6:24cbbdf2dac2 | 243 | lcd.locate(11,2); |
claraluques | 6:24cbbdf2dac2 | 244 | lcd.printf("Concluir"); |
claraluques | 6:24cbbdf2dac2 | 245 | lcd.locate(11,3); |
claraluques | 6:24cbbdf2dac2 | 246 | lcd.printf("Cancelar"); |
claraluques | 7:e2c1b0338286 | 247 | movercursor(1,3,10); |
claraluques | 6:24cbbdf2dac2 | 248 | if (bot_enter!=penter){ |
claraluques | 6:24cbbdf2dac2 | 249 | if (linha==1){ |
claraluques | 6:24cbbdf2dac2 | 250 | func = 5; |
claraluques | 8:b80f50544ddd | 251 | cx_salva = cx; |
claraluques | 8:b80f50544ddd | 252 | cy_salva = cy; |
claraluques | 8:b80f50544ddd | 253 | cz_salva = cz; |
claraluques | 6:24cbbdf2dac2 | 254 | } |
claraluques | 6:24cbbdf2dac2 | 255 | else if (linha==2) { |
claraluques | 8:b80f50544ddd | 256 | func = 7; |
claraluques | 6:24cbbdf2dac2 | 257 | } |
claraluques | 6:24cbbdf2dac2 | 258 | else if (linha==3) { |
claraluques | 8:b80f50544ddd | 259 | func = 1; |
claraluques | 6:24cbbdf2dac2 | 260 | } |
claraluques | 6:24cbbdf2dac2 | 261 | } |
claraluques | 6:24cbbdf2dac2 | 262 | |
claraluques | 6:24cbbdf2dac2 | 263 | } |
claraluques | 6:24cbbdf2dac2 | 264 | |
claraluques | 9:86b5a317fcd4 | 265 | //func 3 |
claraluques | 9:86b5a317fcd4 | 266 | |
claraluques | 9:86b5a317fcd4 | 267 | //func 4 |
claraluques | 9:86b5a317fcd4 | 268 | |
claraluques | 8:b80f50544ddd | 269 | //func 5 |
claraluques | 9:86b5a317fcd4 | 270 | void telasalvamento(){ //função para quando salvar um ponto |
claraluques | 8:b80f50544ddd | 271 | lcd.cls(); |
claraluques | 8:b80f50544ddd | 272 | lcd.locate(0,0); |
claraluques | 8:b80f50544ddd | 273 | lcd.printf("Voce salvou o ponto:"); |
claraluques | 9:86b5a317fcd4 | 274 | lcd.locate(5,1); |
claraluques | 9:86b5a317fcd4 | 275 | lcd.printf("X: %.3f", cx_salva); |
claraluques | 9:86b5a317fcd4 | 276 | lcd.locate(5,2); |
claraluques | 9:86b5a317fcd4 | 277 | lcd.printf("Y: %.3f", cy_salva); |
claraluques | 9:86b5a317fcd4 | 278 | lcd.locate(5,3); |
claraluques | 9:86b5a317fcd4 | 279 | lcd.printf("Z: %.3f", cz_salva); |
claraluques | 9:86b5a317fcd4 | 280 | wait(1); |
claraluques | 8:b80f50544ddd | 281 | func = 6; |
claraluques | 8:b80f50544ddd | 282 | } |
claraluques | 8:b80f50544ddd | 283 | |
claraluques | 9:86b5a317fcd4 | 284 | //func 6 |
claraluques | 9:86b5a317fcd4 | 285 | void telacola(){ //tela para escolher o tipo de sequencia da cola |
claraluques | 9:86b5a317fcd4 | 286 | lcd.cls(); |
claraluques | 9:86b5a317fcd4 | 287 | bot_enter = 0; |
claraluques | 9:86b5a317fcd4 | 288 | lcd.printf("P/ o proximo ponto:"); |
claraluques | 9:86b5a317fcd4 | 289 | lcd.locate(3,1); |
claraluques | 9:86b5a317fcd4 | 290 | lcd.printf("Sem cola"); |
claraluques | 9:86b5a317fcd4 | 291 | lcd.locate(3,2); |
claraluques | 9:86b5a317fcd4 | 292 | lcd.printf("Cola no ponto"); |
claraluques | 9:86b5a317fcd4 | 293 | lcd.locate(3,3); |
claraluques | 9:86b5a317fcd4 | 294 | lcd.printf("Cola continua"); |
claraluques | 9:86b5a317fcd4 | 295 | movercursor(1,3,2); |
claraluques | 9:86b5a317fcd4 | 296 | if (bot_enter!=penter){ |
claraluques | 9:86b5a317fcd4 | 297 | if (linha==1){ |
claraluques | 9:86b5a317fcd4 | 298 | cola = 0; |
claraluques | 9:86b5a317fcd4 | 299 | func = 2; |
claraluques | 9:86b5a317fcd4 | 300 | } |
claraluques | 9:86b5a317fcd4 | 301 | else if (linha==2) { |
claraluques | 9:86b5a317fcd4 | 302 | cola = 1; |
claraluques | 9:86b5a317fcd4 | 303 | func = 2; |
claraluques | 9:86b5a317fcd4 | 304 | } |
claraluques | 9:86b5a317fcd4 | 305 | else if (linha==3) { |
claraluques | 9:86b5a317fcd4 | 306 | cola = 2; |
claraluques | 9:86b5a317fcd4 | 307 | func = 2; |
claraluques | 9:86b5a317fcd4 | 308 | } |
claraluques | 9:86b5a317fcd4 | 309 | } |
claraluques | 9:86b5a317fcd4 | 310 | } |
claraluques | 6:24cbbdf2dac2 | 311 | |
claraluques | 9:86b5a317fcd4 | 312 | |
claraluques | 9:86b5a317fcd4 | 313 | //func 7 |
claraluques | 9:86b5a317fcd4 | 314 | void executarprograma() { //tela para selecionar se deseja executar o programa |
claraluques | 9:86b5a317fcd4 | 315 | lcd.cls(); |
claraluques | 9:86b5a317fcd4 | 316 | bot_enter = 0; |
claraluques | 9:86b5a317fcd4 | 317 | lcd.locate(2,0); |
claraluques | 9:86b5a317fcd4 | 318 | lcd.printf("VOCE CONCLUIU SEU"); |
claraluques | 9:86b5a317fcd4 | 319 | lcd.locate(5,1); |
claraluques | 9:86b5a317fcd4 | 320 | lcd.printf("PROGRAMA."); |
claraluques | 9:86b5a317fcd4 | 321 | lcd.locate(0,2); |
claraluques | 9:86b5a317fcd4 | 322 | lcd.printf("Deseja"); |
claraluques | 9:86b5a317fcd4 | 323 | lcd.locate(0,3); |
claraluques | 9:86b5a317fcd4 | 324 | lcd.printf("executa-lo?"); |
claraluques | 9:86b5a317fcd4 | 325 | lcd.locate(14,2); |
claraluques | 9:86b5a317fcd4 | 326 | lcd.printf("Sim"); |
claraluques | 9:86b5a317fcd4 | 327 | lcd.locate(14,3); |
claraluques | 9:86b5a317fcd4 | 328 | lcd.printf("Voltar"); |
claraluques | 9:86b5a317fcd4 | 329 | movercursor(2,3,13); |
claraluques | 9:86b5a317fcd4 | 330 | if (bot_enter!=penter) { |
claraluques | 9:86b5a317fcd4 | 331 | if (linha==2){ |
claraluques | 9:86b5a317fcd4 | 332 | exec = 1; |
claraluques | 9:86b5a317fcd4 | 333 | func = 9; |
claraluques | 9:86b5a317fcd4 | 334 | } |
claraluques | 9:86b5a317fcd4 | 335 | else if (linha==3){ |
claraluques | 9:86b5a317fcd4 | 336 | exec = 0; |
claraluques | 9:86b5a317fcd4 | 337 | func = 2; |
claraluques | 9:86b5a317fcd4 | 338 | } |
claraluques | 9:86b5a317fcd4 | 339 | } |
claraluques | 9:86b5a317fcd4 | 340 | } |
claraluques | 9:86b5a317fcd4 | 341 | |
claraluques | 9:86b5a317fcd4 | 342 | //func 8 |
claraluques | 9:86b5a317fcd4 | 343 | void telazerar(){ //tela para zerar a máquina |
claraluques | 9:86b5a317fcd4 | 344 | lcd.cls(); |
claraluques | 9:86b5a317fcd4 | 345 | bot_enter = 0; |
claraluques | 9:86b5a317fcd4 | 346 | lcd.locate(2,0); |
claraluques | 9:86b5a317fcd4 | 347 | lcd.printf("Pressione OK para zerar as coordenadas"); |
claraluques | 9:86b5a317fcd4 | 348 | lcd.locate(7,2); |
claraluques | 9:86b5a317fcd4 | 349 | lcd.printf("OK"); |
claraluques | 9:86b5a317fcd4 | 350 | lcd.locate(7,3); |
claraluques | 9:86b5a317fcd4 | 351 | lcd.printf("Voltar"); |
claraluques | 9:86b5a317fcd4 | 352 | movercursor(2,3,6); |
claraluques | 9:86b5a317fcd4 | 353 | if (bot_enter!=penter) { |
claraluques | 9:86b5a317fcd4 | 354 | if (linha==2){ |
claraluques | 9:86b5a317fcd4 | 355 | cx = 0; |
claraluques | 9:86b5a317fcd4 | 356 | cy = 0; |
claraluques | 9:86b5a317fcd4 | 357 | cz = 0; |
claraluques | 9:86b5a317fcd4 | 358 | func = 10; |
claraluques | 9:86b5a317fcd4 | 359 | } |
claraluques | 9:86b5a317fcd4 | 360 | else if (linha==3){ |
claraluques | 9:86b5a317fcd4 | 361 | func = 1; |
claraluques | 9:86b5a317fcd4 | 362 | } |
claraluques | 9:86b5a317fcd4 | 363 | } |
claraluques | 9:86b5a317fcd4 | 364 | } |
claraluques | 9:86b5a317fcd4 | 365 | |
claraluques | 9:86b5a317fcd4 | 366 | |
claraluques | 9:86b5a317fcd4 | 367 | //func 9 |
claraluques | 9:86b5a317fcd4 | 368 | void executando(){ //tela de executando |
claraluques | 9:86b5a317fcd4 | 369 | lcd.cls(); |
claraluques | 9:86b5a317fcd4 | 370 | lcd.locate(4,1); |
claraluques | 9:86b5a317fcd4 | 371 | lcd.printf("Executando"); |
claraluques | 9:86b5a317fcd4 | 372 | int contador = 0; |
claraluques | 9:86b5a317fcd4 | 373 | while (exec==1){ |
claraluques | 9:86b5a317fcd4 | 374 | lcd.locate(14,1); |
claraluques | 9:86b5a317fcd4 | 375 | lcd.printf(". "); |
claraluques | 9:86b5a317fcd4 | 376 | wait(0.5); |
claraluques | 9:86b5a317fcd4 | 377 | lcd.locate(14,1); |
claraluques | 9:86b5a317fcd4 | 378 | lcd.printf(".. "); |
claraluques | 9:86b5a317fcd4 | 379 | wait(0.5); |
claraluques | 9:86b5a317fcd4 | 380 | lcd.locate(14,1); |
claraluques | 9:86b5a317fcd4 | 381 | lcd.printf("..."); |
claraluques | 9:86b5a317fcd4 | 382 | wait(0.5); |
claraluques | 9:86b5a317fcd4 | 383 | lcd.locate(14,1); |
claraluques | 9:86b5a317fcd4 | 384 | lcd.printf(" "); |
claraluques | 9:86b5a317fcd4 | 385 | wait(0.5); |
claraluques | 9:86b5a317fcd4 | 386 | contador++; |
claraluques | 9:86b5a317fcd4 | 387 | if (contador>=2){ |
claraluques | 9:86b5a317fcd4 | 388 | exec = 0; |
claraluques | 9:86b5a317fcd4 | 389 | func = 11; |
claraluques | 9:86b5a317fcd4 | 390 | } |
claraluques | 9:86b5a317fcd4 | 391 | } |
claraluques | 9:86b5a317fcd4 | 392 | } |
claraluques | 9:86b5a317fcd4 | 393 | |
claraluques | 9:86b5a317fcd4 | 394 | //func 10 |
claraluques | 9:86b5a317fcd4 | 395 | void zerado() { //tela avisando que a máquina foi zerada |
claraluques | 9:86b5a317fcd4 | 396 | lcd.cls(); |
claraluques | 9:86b5a317fcd4 | 397 | lcd.locate(5,1); |
claraluques | 9:86b5a317fcd4 | 398 | lcd.printf("Voce zerou"); |
claraluques | 9:86b5a317fcd4 | 399 | lcd.locate(5,2); |
claraluques | 9:86b5a317fcd4 | 400 | lcd.printf("a maquina!"); |
claraluques | 9:86b5a317fcd4 | 401 | wait(1); |
claraluques | 9:86b5a317fcd4 | 402 | func = 8; |
claraluques | 9:86b5a317fcd4 | 403 | } |
claraluques | 9:86b5a317fcd4 | 404 | |
claraluques | 9:86b5a317fcd4 | 405 | //func 11 |
claraluques | 9:86b5a317fcd4 | 406 | void finalizado() { |
claraluques | 9:86b5a317fcd4 | 407 | lcd.cls(); |
claraluques | 9:86b5a317fcd4 | 408 | lcd.locate(6,1); |
claraluques | 9:86b5a317fcd4 | 409 | lcd.printf("PROGRAMA"); |
claraluques | 9:86b5a317fcd4 | 410 | lcd.locate(5,2); |
claraluques | 9:86b5a317fcd4 | 411 | lcd.printf("FINALIZADO"); |
claraluques | 9:86b5a317fcd4 | 412 | wait(1); |
claraluques | 9:86b5a317fcd4 | 413 | func = 1; |
claraluques | 9:86b5a317fcd4 | 414 | } |
claraluques | 9:86b5a317fcd4 | 415 | |
claraluques | 9:86b5a317fcd4 | 416 | Menu(); //não apagar |
claraluques | 5:30f5ffe0ea0b | 417 | }; |
wim | 1:ef419b21167d | 418 | |
claraluques | 9:86b5a317fcd4 | 419 | Menu::Menu(){ //não apagar |
claraluques | 10:97002056ecda | 420 | func = 0 |
claraluques | 9:86b5a317fcd4 | 421 | } |
wim | 3:f238b4f7874f | 422 | |
claraluques | 5:30f5ffe0ea0b | 423 | Menu menu; |
wim | 3:f238b4f7874f | 424 | |
claraluques | 5:30f5ffe0ea0b | 425 | int main () { |
claraluques | 5:30f5ffe0ea0b | 426 | lcd.setBacklight(TextLCD::LightOn); //liga backlight |
claraluques | 9:86b5a317fcd4 | 427 | lcd.setCursor(TextLCD::CurOff_BlkOff); //define tipo de cursor |
claraluques | 5:30f5ffe0ea0b | 428 | |
claraluques | 9:86b5a317fcd4 | 429 | botao_enter.rise(&botenter_press); //chama função botao enter |
claraluques | 6:24cbbdf2dac2 | 430 | //botao_enter.fall(&botenter_solto); |
claraluques | 5:30f5ffe0ea0b | 431 | |
claraluques | 9:86b5a317fcd4 | 432 | botao_cima.rise(&botcima_press); //chama função botao para cima |
claraluques | 6:24cbbdf2dac2 | 433 | //botao_cima.fall(&botcima_solto); |
claraluques | 5:30f5ffe0ea0b | 434 | |
claraluques | 9:86b5a317fcd4 | 435 | botao_baixo.rise(&botbaixo_press); //chama função bota para baixo |
claraluques | 6:24cbbdf2dac2 | 436 | //botao_baixo.fall(&botbaixo_solto); |
claraluques | 6:24cbbdf2dac2 | 437 | |
claraluques | 5:30f5ffe0ea0b | 438 | |
claraluques | 5:30f5ffe0ea0b | 439 | while(1){ |
claraluques | 5:30f5ffe0ea0b | 440 | //printf("%d %d %d \n\r", bot_enter, bot_cima, bot_baixo); |
claraluques | 9:86b5a317fcd4 | 441 | switch(menu.func){ //faz com que as telas sejam iniciadas |
claraluques | 5:30f5ffe0ea0b | 442 | case 0: menu.inicializar(); break; |
claraluques | 5:30f5ffe0ea0b | 443 | case 1: menu.menuprincipal(); break; |
claraluques | 6:24cbbdf2dac2 | 444 | case 2: menu.jog(); break; |
claraluques | 9:86b5a317fcd4 | 445 | //case 3: menu.automatico(); break; |
claraluques | 9:86b5a317fcd4 | 446 | //case 4: menu.config(); break; |
claraluques | 9:86b5a317fcd4 | 447 | case 5: menu.telasalvamento(); break; |
claraluques | 9:86b5a317fcd4 | 448 | case 6: menu.telacola(); break; |
claraluques | 9:86b5a317fcd4 | 449 | case 7: menu.executarprograma(); break; |
claraluques | 9:86b5a317fcd4 | 450 | case 8: menu.telazerar(); break; |
claraluques | 9:86b5a317fcd4 | 451 | case 9: menu.executando(); break; |
claraluques | 9:86b5a317fcd4 | 452 | case 10: menu.zerado(); break; |
claraluques | 9:86b5a317fcd4 | 453 | case 11: menu.finalizado(); break; |
claraluques | 9:86b5a317fcd4 | 454 | |
claraluques | 5:30f5ffe0ea0b | 455 | } |
claraluques | 5:30f5ffe0ea0b | 456 | } |
claraluques | 5:30f5ffe0ea0b | 457 | } |
claraluques | 5:30f5ffe0ea0b | 458 | |
claraluques | 5:30f5ffe0ea0b | 459 | |
claraluques | 5:30f5ffe0ea0b | 460 | |
claraluques | 5:30f5ffe0ea0b | 461 | |
claraluques | 5:30f5ffe0ea0b | 462 | |
claraluques | 5:30f5ffe0ea0b | 463 | |
claraluques | 5:30f5ffe0ea0b | 464 | //função interrupt botão enter |
claraluques | 5:30f5ffe0ea0b | 465 | |
claraluques | 5:30f5ffe0ea0b | 466 | void botenter_press(void){ |
claraluques | 9:86b5a317fcd4 | 467 | |
claraluques | 6:24cbbdf2dac2 | 468 | penter = bot_enter; |
claraluques | 6:24cbbdf2dac2 | 469 | bot_enter = !bot_enter; |
claraluques | 5:30f5ffe0ea0b | 470 | printf("enter high"); |
claraluques | 5:30f5ffe0ea0b | 471 | } |
claraluques | 6:24cbbdf2dac2 | 472 | /*void botenter_solto(void) { |
claraluques | 6:24cbbdf2dac2 | 473 | penter = bot_enter; |
claraluques | 6:24cbbdf2dac2 | 474 | bot_enter = !bot_enter; |
claraluques | 5:30f5ffe0ea0b | 475 | printf("enter low"); |
claraluques | 6:24cbbdf2dac2 | 476 | }*/ |
claraluques | 5:30f5ffe0ea0b | 477 | |
claraluques | 5:30f5ffe0ea0b | 478 | //função interrupt botão cima |
claraluques | 5:30f5ffe0ea0b | 479 | |
claraluques | 5:30f5ffe0ea0b | 480 | void botcima_press(void){ |
claraluques | 6:24cbbdf2dac2 | 481 | pcima = bot_cima; |
claraluques | 6:24cbbdf2dac2 | 482 | bot_cima = !bot_cima; |
claraluques | 5:30f5ffe0ea0b | 483 | printf("cima high"); |
claraluques | 5:30f5ffe0ea0b | 484 | } |
claraluques | 6:24cbbdf2dac2 | 485 | /*void botcima_solto(void) { |
claraluques | 6:24cbbdf2dac2 | 486 | pcima = bot_cima; |
claraluques | 6:24cbbdf2dac2 | 487 | bot_cima = !bot_cima; |
claraluques | 5:30f5ffe0ea0b | 488 | printf("cima low"); |
claraluques | 6:24cbbdf2dac2 | 489 | }*/ |
wim | 0:a75049de1a82 | 490 | |
claraluques | 5:30f5ffe0ea0b | 491 | //função interrupt botão baixo |
claraluques | 5:30f5ffe0ea0b | 492 | |
claraluques | 5:30f5ffe0ea0b | 493 | void botbaixo_press(void){ |
claraluques | 6:24cbbdf2dac2 | 494 | pbaixo = bot_baixo; |
claraluques | 6:24cbbdf2dac2 | 495 | bot_baixo = !bot_baixo; |
claraluques | 5:30f5ffe0ea0b | 496 | printf("baixo high"); |
claraluques | 5:30f5ffe0ea0b | 497 | } |
claraluques | 6:24cbbdf2dac2 | 498 | /*void botbaixo_solto(void) { |
claraluques | 6:24cbbdf2dac2 | 499 | pbaixo = bot_baixo; |
claraluques | 6:24cbbdf2dac2 | 500 | bot_baixo = !bot_baixo; |
claraluques | 5:30f5ffe0ea0b | 501 | printf("baixo low"); |
claraluques | 6:24cbbdf2dac2 | 502 | }*/ |
claraluques | 5:30f5ffe0ea0b | 503 | |
claraluques | 5:30f5ffe0ea0b | 504 |