Código para o menu no LCD
Dependencies: mbed SDFileSystemSD TextLCD
Fork of TextLCD_HelloWorld2 by
main.cpp@5:30f5ffe0ea0b, 2018-05-09 (annotated)
- Committer:
- claraluques
- Date:
- Wed May 09 20:27:39 2018 +0000
- Revision:
- 5:30f5ffe0ea0b
- Parent:
- 4:a3e4bb2053cb
- Child:
- 6:24cbbdf2dac2
arrumar botoes
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; |
wim | 0:a75049de1a82 | 108 | |
claraluques | 5:30f5ffe0ea0b | 109 | //variáveis float |
claraluques | 5:30f5ffe0ea0b | 110 | float cx = 123; |
claraluques | 5:30f5ffe0ea0b | 111 | float cy = 456; |
claraluques | 5:30f5ffe0ea0b | 112 | float cz = 789; |
claraluques | 5:30f5ffe0ea0b | 113 | |
claraluques | 5:30f5ffe0ea0b | 114 | //funções interrupt |
claraluques | 5:30f5ffe0ea0b | 115 | void botenter_press(void); |
claraluques | 5:30f5ffe0ea0b | 116 | void botenter_solto(void); |
wim | 0:a75049de1a82 | 117 | |
claraluques | 5:30f5ffe0ea0b | 118 | void botcima_press(void); |
claraluques | 5:30f5ffe0ea0b | 119 | void botcima_solto(void); |
claraluques | 5:30f5ffe0ea0b | 120 | |
claraluques | 5:30f5ffe0ea0b | 121 | void botbaixo_press(void); |
claraluques | 5:30f5ffe0ea0b | 122 | void botbaixo_solto(void); |
claraluques | 5:30f5ffe0ea0b | 123 | |
claraluques | 5:30f5ffe0ea0b | 124 | //criar classe "menu" (funções das telas) |
claraluques | 5:30f5ffe0ea0b | 125 | class Menu{ |
claraluques | 5:30f5ffe0ea0b | 126 | public: |
claraluques | 5:30f5ffe0ea0b | 127 | int linha; |
claraluques | 5:30f5ffe0ea0b | 128 | int coluna; |
claraluques | 5:30f5ffe0ea0b | 129 | int func; |
wim | 4:a3e4bb2053cb | 130 | |
claraluques | 5:30f5ffe0ea0b | 131 | void movercursor(int min, int max){ //função para mover cursor de seleção |
claraluques | 5:30f5ffe0ea0b | 132 | coluna = 0; |
claraluques | 5:30f5ffe0ea0b | 133 | linha = min; |
claraluques | 5:30f5ffe0ea0b | 134 | while (bot_enter==0){ |
claraluques | 5:30f5ffe0ea0b | 135 | if (bot_cima==1){ |
claraluques | 5:30f5ffe0ea0b | 136 | if (linha==min){ |
claraluques | 5:30f5ffe0ea0b | 137 | linha=max; |
claraluques | 5:30f5ffe0ea0b | 138 | } |
claraluques | 5:30f5ffe0ea0b | 139 | else { |
claraluques | 5:30f5ffe0ea0b | 140 | linha--; |
claraluques | 5:30f5ffe0ea0b | 141 | } |
wim | 3:f238b4f7874f | 142 | |
claraluques | 5:30f5ffe0ea0b | 143 | } |
claraluques | 5:30f5ffe0ea0b | 144 | if (bot_baixo==1){ |
claraluques | 5:30f5ffe0ea0b | 145 | if (linha==max){ |
claraluques | 5:30f5ffe0ea0b | 146 | linha=min; |
claraluques | 5:30f5ffe0ea0b | 147 | } |
claraluques | 5:30f5ffe0ea0b | 148 | else { |
claraluques | 5:30f5ffe0ea0b | 149 | linha++; |
claraluques | 5:30f5ffe0ea0b | 150 | } |
claraluques | 5:30f5ffe0ea0b | 151 | } |
claraluques | 5:30f5ffe0ea0b | 152 | lcd.locate(coluna, linha); |
claraluques | 5:30f5ffe0ea0b | 153 | lcd.printf("%c", 0x3E); |
claraluques | 5:30f5ffe0ea0b | 154 | printf("%d \n\r",linha); |
claraluques | 5:30f5ffe0ea0b | 155 | printf("%d %d %d \n\r", bot_enter, bot_cima, bot_baixo); |
claraluques | 5:30f5ffe0ea0b | 156 | wait(2); |
claraluques | 5:30f5ffe0ea0b | 157 | } |
claraluques | 5:30f5ffe0ea0b | 158 | //printf("%d \n\r",linha); |
claraluques | 5:30f5ffe0ea0b | 159 | } |
claraluques | 5:30f5ffe0ea0b | 160 | |
claraluques | 5:30f5ffe0ea0b | 161 | |
claraluques | 5:30f5ffe0ea0b | 162 | //func 0 |
claraluques | 5:30f5ffe0ea0b | 163 | void inicializar(){ //função tela incial de boas-vindas |
claraluques | 5:30f5ffe0ea0b | 164 | lcd.cls(); |
claraluques | 5:30f5ffe0ea0b | 165 | lcd.locate(9,0); |
claraluques | 5:30f5ffe0ea0b | 166 | lcd.printf("Ola!"); |
claraluques | 5:30f5ffe0ea0b | 167 | lcd.locate(0,1); |
claraluques | 5:30f5ffe0ea0b | 168 | lcd.printf("Utilize seu EPI ao operar a maquina."); |
claraluques | 5:30f5ffe0ea0b | 169 | wait(5); |
claraluques | 5:30f5ffe0ea0b | 170 | func = 1; |
claraluques | 5:30f5ffe0ea0b | 171 | } |
claraluques | 5:30f5ffe0ea0b | 172 | |
claraluques | 5:30f5ffe0ea0b | 173 | //func 1 |
claraluques | 5:30f5ffe0ea0b | 174 | void menuprincipal(){ //função menu principal |
claraluques | 5:30f5ffe0ea0b | 175 | lcd.cls(); |
claraluques | 5:30f5ffe0ea0b | 176 | lcd.locate(1,0); |
claraluques | 5:30f5ffe0ea0b | 177 | lcd.printf("Modo JOG"); |
claraluques | 5:30f5ffe0ea0b | 178 | lcd.locate(1,1); |
claraluques | 5:30f5ffe0ea0b | 179 | lcd.printf("Modo Automatico"); |
claraluques | 5:30f5ffe0ea0b | 180 | lcd.locate(1,2); |
claraluques | 5:30f5ffe0ea0b | 181 | lcd.printf("Config"); |
claraluques | 5:30f5ffe0ea0b | 182 | movercursor(0,2); |
claraluques | 5:30f5ffe0ea0b | 183 | if (bot_enter==1){ |
claraluques | 5:30f5ffe0ea0b | 184 | if (linha==0){ |
claraluques | 5:30f5ffe0ea0b | 185 | func = 2; |
claraluques | 5:30f5ffe0ea0b | 186 | } |
claraluques | 5:30f5ffe0ea0b | 187 | else if (linha==1) { |
claraluques | 5:30f5ffe0ea0b | 188 | func = 3; |
claraluques | 5:30f5ffe0ea0b | 189 | } |
claraluques | 5:30f5ffe0ea0b | 190 | else if (linha==2) { |
claraluques | 5:30f5ffe0ea0b | 191 | func = 4; |
claraluques | 5:30f5ffe0ea0b | 192 | } |
claraluques | 5:30f5ffe0ea0b | 193 | } |
claraluques | 5:30f5ffe0ea0b | 194 | } |
claraluques | 5:30f5ffe0ea0b | 195 | Menu(); |
claraluques | 5:30f5ffe0ea0b | 196 | }; |
wim | 1:ef419b21167d | 197 | |
claraluques | 5:30f5ffe0ea0b | 198 | Menu::Menu(){ |
claraluques | 5:30f5ffe0ea0b | 199 | func = 0; |
wim | 4:a3e4bb2053cb | 200 | } |
wim | 3:f238b4f7874f | 201 | |
claraluques | 5:30f5ffe0ea0b | 202 | Menu menu; |
wim | 3:f238b4f7874f | 203 | |
claraluques | 5:30f5ffe0ea0b | 204 | int main () { |
claraluques | 5:30f5ffe0ea0b | 205 | lcd.setBacklight(TextLCD::LightOn); //liga backlight |
claraluques | 5:30f5ffe0ea0b | 206 | lcd.setCursor(TextLCD::CurOff_BlkOff); |
claraluques | 5:30f5ffe0ea0b | 207 | |
claraluques | 5:30f5ffe0ea0b | 208 | botao_enter.rise(&botenter_press); |
claraluques | 5:30f5ffe0ea0b | 209 | botao_enter.fall(&botenter_solto); |
claraluques | 5:30f5ffe0ea0b | 210 | |
claraluques | 5:30f5ffe0ea0b | 211 | botao_cima.rise(&botcima_press); |
claraluques | 5:30f5ffe0ea0b | 212 | botao_cima.fall(&botcima_solto); |
claraluques | 5:30f5ffe0ea0b | 213 | |
claraluques | 5:30f5ffe0ea0b | 214 | botao_baixo.rise(&botbaixo_press); |
claraluques | 5:30f5ffe0ea0b | 215 | botao_baixo.fall(&botbaixo_solto); |
claraluques | 5:30f5ffe0ea0b | 216 | |
claraluques | 5:30f5ffe0ea0b | 217 | |
claraluques | 5:30f5ffe0ea0b | 218 | while(1){ |
claraluques | 5:30f5ffe0ea0b | 219 | //printf("%d %d %d \n\r", bot_enter, bot_cima, bot_baixo); |
claraluques | 5:30f5ffe0ea0b | 220 | switch(menu.func){ |
claraluques | 5:30f5ffe0ea0b | 221 | case 0: menu.inicializar(); break; |
claraluques | 5:30f5ffe0ea0b | 222 | case 1: menu.menuprincipal(); break; |
claraluques | 5:30f5ffe0ea0b | 223 | //case 2: menu.notReferenced(); break; |
claraluques | 5:30f5ffe0ea0b | 224 | //case 3: menu.notReferenced(2); break; |
claraluques | 5:30f5ffe0ea0b | 225 | //case 4: menu.notReferenced(3); break; |
claraluques | 5:30f5ffe0ea0b | 226 | //case 5: menu.referencing(); break; |
claraluques | 5:30f5ffe0ea0b | 227 | //case 6: menu.rootMenu(); break; |
claraluques | 5:30f5ffe0ea0b | 228 | //case 7: menu.manualControl(); break; |
claraluques | 5:30f5ffe0ea0b | 229 | //case 8: menu.positions(); break; |
claraluques | 5:30f5ffe0ea0b | 230 | //case 9: menu.selectPos(); break; |
claraluques | 5:30f5ffe0ea0b | 231 | //case 10: menu.selectPos(2); break; |
claraluques | 5:30f5ffe0ea0b | 232 | //case 11: menu.selectPos(3); break; |
claraluques | 5:30f5ffe0ea0b | 233 | //case 12: menu.run(); break; |
claraluques | 5:30f5ffe0ea0b | 234 | } |
claraluques | 5:30f5ffe0ea0b | 235 | } |
claraluques | 5:30f5ffe0ea0b | 236 | } |
claraluques | 5:30f5ffe0ea0b | 237 | |
claraluques | 5:30f5ffe0ea0b | 238 | |
claraluques | 5:30f5ffe0ea0b | 239 | |
claraluques | 5:30f5ffe0ea0b | 240 | |
claraluques | 5:30f5ffe0ea0b | 241 | |
claraluques | 5:30f5ffe0ea0b | 242 | |
claraluques | 5:30f5ffe0ea0b | 243 | //função interrupt botão enter |
claraluques | 5:30f5ffe0ea0b | 244 | |
claraluques | 5:30f5ffe0ea0b | 245 | void botenter_press(void){ |
claraluques | 5:30f5ffe0ea0b | 246 | bot_enter = 1; |
claraluques | 5:30f5ffe0ea0b | 247 | printf("enter high"); |
claraluques | 5:30f5ffe0ea0b | 248 | } |
claraluques | 5:30f5ffe0ea0b | 249 | void botenter_solto(void) { |
claraluques | 5:30f5ffe0ea0b | 250 | bot_enter = 0; |
claraluques | 5:30f5ffe0ea0b | 251 | printf("enter low"); |
claraluques | 5:30f5ffe0ea0b | 252 | } |
claraluques | 5:30f5ffe0ea0b | 253 | |
claraluques | 5:30f5ffe0ea0b | 254 | //função interrupt botão cima |
claraluques | 5:30f5ffe0ea0b | 255 | |
claraluques | 5:30f5ffe0ea0b | 256 | void botcima_press(void){ |
claraluques | 5:30f5ffe0ea0b | 257 | bot_cima = 1; |
claraluques | 5:30f5ffe0ea0b | 258 | printf("cima high"); |
claraluques | 5:30f5ffe0ea0b | 259 | } |
claraluques | 5:30f5ffe0ea0b | 260 | void botcima_solto(void) { |
claraluques | 5:30f5ffe0ea0b | 261 | bot_cima = 0; |
claraluques | 5:30f5ffe0ea0b | 262 | printf("cima low"); |
claraluques | 5:30f5ffe0ea0b | 263 | } |
wim | 0:a75049de1a82 | 264 | |
claraluques | 5:30f5ffe0ea0b | 265 | //função interrupt botão baixo |
claraluques | 5:30f5ffe0ea0b | 266 | |
claraluques | 5:30f5ffe0ea0b | 267 | void botbaixo_press(void){ |
claraluques | 5:30f5ffe0ea0b | 268 | bot_baixo = 1; |
claraluques | 5:30f5ffe0ea0b | 269 | printf("baixo high"); |
claraluques | 5:30f5ffe0ea0b | 270 | } |
claraluques | 5:30f5ffe0ea0b | 271 | void botbaixo_solto(void) { |
claraluques | 5:30f5ffe0ea0b | 272 | bot_baixo = 0; |
claraluques | 5:30f5ffe0ea0b | 273 | printf("baixo low"); |
claraluques | 5:30f5ffe0ea0b | 274 | } |
claraluques | 5:30f5ffe0ea0b | 275 | |
claraluques | 5:30f5ffe0ea0b | 276 |