Código para o menu no LCD

Dependencies:   mbed SDFileSystemSD TextLCD

Fork of TextLCD_HelloWorld2 by Wim Huiskamp

Committer:
claraluques
Date:
Wed May 23 14:54:13 2018 +0000
Revision:
32:c293f89170b0
Parent:
31:77eb51d4ee18
Child:
33:0149960e95c1
est? salvando programa com nome, mas ? necessario segurar e clicar para sair da tela. tamb?m, arrumar o fato de salvar uma letra a mais qnd segura.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
claraluques 11:6b7accf18fe2 1 /*CÓDIGO PARA LCD MENU HELLEN - GRUPO T*/
claraluques 11:6b7accf18fe2 2
wim 0:a75049de1a82 3 #include "mbed.h"
wim 0:a75049de1a82 4 #include "TextLCD.h"
lucasfontenla 28:b3c51076ebe8 5 #include "SDFileSystem.h"
claraluques 19:2c890ae2d187 6 #include "string"
lucasfontenla 29:558eccdfc079 7 #include "vector"
claraluques 11:6b7accf18fe2 8
claraluques 32:c293f89170b0 9 Timer timer;
claraluques 32:c293f89170b0 10
claraluques 5:30f5ffe0ea0b 11 // Host PC Communication channels
claraluques 11:6b7accf18fe2 12 Serial pc(USBTX, USBRX); // tx, rx //não apagar
wim 4:a3e4bb2053cb 13
claraluques 5:30f5ffe0ea0b 14 //I2C Communication
claraluques 11:6b7accf18fe2 15 I2C i2c_lcd(D14,D15); // SDA, SCL //não apagar
claraluques 5:30f5ffe0ea0b 16
claraluques 5:30f5ffe0ea0b 17 //Botão push
claraluques 5:30f5ffe0ea0b 18 InterruptIn botao_enter(D13);
claraluques 31:77eb51d4ee18 19 InterruptIn botao_cima(D12);
claraluques 5:30f5ffe0ea0b 20 InterruptIn botao_baixo(D9);
claraluques 5:30f5ffe0ea0b 21
claraluques 5:30f5ffe0ea0b 22 //LCD instantiation
claraluques 11:6b7accf18fe2 23 TextLCD_I2C lcd(&i2c_lcd, 0x7E, TextLCD::LCD20x4); //não apagar
claraluques 5:30f5ffe0ea0b 24
claraluques 5:30f5ffe0ea0b 25 //variáveis int
claraluques 31:77eb51d4ee18 26 int bot_enter = 0;
claraluques 31:77eb51d4ee18 27 int bot_cima = 0;
claraluques 31:77eb51d4ee18 28 int bot_baixo = 0;
claraluques 31:77eb51d4ee18 29 int penter = 1;
claraluques 31:77eb51d4ee18 30 int pcima = 1;
claraluques 31:77eb51d4ee18 31 int pbaixo = 1;
claraluques 9:86b5a317fcd4 32 int cola;
claraluques 9:86b5a317fcd4 33 int exec;
claraluques 12:64ed645e79ad 34 int select = 0;
claraluques 26:59081efdce79 35 int pontos = 0;
claraluques 26:59081efdce79 36 int salvar = 0;
claraluques 26:59081efdce79 37 int maxpontos = 5;
claraluques 26:59081efdce79 38 int home;
claraluques 32:c293f89170b0 39 int coluna = 1;
claraluques 32:c293f89170b0 40 int contador = 0;
claraluques 32:c293f89170b0 41 int sair = 0;
wim 0:a75049de1a82 42
claraluques 5:30f5ffe0ea0b 43 //variáveis float
claraluques 7:e2c1b0338286 44 float cx = 120.458;
claraluques 7:e2c1b0338286 45 float cy = 457.854;
claraluques 7:e2c1b0338286 46 float cz = 782.659;
claraluques 8:b80f50544ddd 47 float cx_salva;
claraluques 8:b80f50544ddd 48 float cy_salva;
claraluques 8:b80f50544ddd 49 float cz_salva;
claraluques 5:30f5ffe0ea0b 50
claraluques 5:30f5ffe0ea0b 51 //funções interrupt
claraluques 5:30f5ffe0ea0b 52 void botenter_press(void);
claraluques 32:c293f89170b0 53 void botcima_press(void);
claraluques 32:c293f89170b0 54 void botbaixo_press(void);
claraluques 32:c293f89170b0 55 void botenter_release(void);
wim 0:a75049de1a82 56
claraluques 5:30f5ffe0ea0b 57
claraluques 19:2c890ae2d187 58 #include "classes.h"
claraluques 19:2c890ae2d187 59
claraluques 9:86b5a317fcd4 60 Menu::Menu(){ //não apagar
claraluques 12:64ed645e79ad 61 func = 0;
claraluques 9:86b5a317fcd4 62 }
wim 3:f238b4f7874f 63
claraluques 5:30f5ffe0ea0b 64 Menu menu;
claraluques 19:2c890ae2d187 65
claraluques 5:30f5ffe0ea0b 66 int main () {
claraluques 5:30f5ffe0ea0b 67 lcd.setBacklight(TextLCD::LightOn); //liga backlight
claraluques 9:86b5a317fcd4 68 lcd.setCursor(TextLCD::CurOff_BlkOff); //define tipo de cursor
claraluques 5:30f5ffe0ea0b 69
claraluques 31:77eb51d4ee18 70 botao_enter.fall(&botenter_press); //chama função botao enter
claraluques 31:77eb51d4ee18 71 botao_cima.fall(&botcima_press); //chama função botao para cima
claraluques 31:77eb51d4ee18 72 botao_baixo.fall(&botbaixo_press); //chama função bota para baixo
claraluques 32:c293f89170b0 73 botao_enter.rise(&botenter_release); //chama função ler timer
claraluques 32:c293f89170b0 74
claraluques 6:24cbbdf2dac2 75
claraluques 5:30f5ffe0ea0b 76 while(1){
claraluques 9:86b5a317fcd4 77 switch(menu.func){ //faz com que as telas sejam iniciadas
claraluques 5:30f5ffe0ea0b 78 case 0: menu.inicializar(); break;
claraluques 5:30f5ffe0ea0b 79 case 1: menu.menuprincipal(); break;
claraluques 6:24cbbdf2dac2 80 case 2: menu.jog(); break;
claraluques 12:64ed645e79ad 81 case 3: menu.automatico(); break;
claraluques 13:1670c34440a5 82 case 4: menu.config(); break;
claraluques 9:86b5a317fcd4 83 case 5: menu.telasalvamento(); break;
claraluques 9:86b5a317fcd4 84 case 6: menu.telacola(); break;
claraluques 9:86b5a317fcd4 85 case 7: menu.executarprograma(); break;
claraluques 9:86b5a317fcd4 86 case 8: menu.telazerar(); break;
claraluques 9:86b5a317fcd4 87 case 9: menu.executando(); break;
claraluques 9:86b5a317fcd4 88 case 10: menu.zerado(); break;
claraluques 9:86b5a317fcd4 89 case 11: menu.finalizado(); break;
claraluques 27:83d2a710cc2f 90 case 15: menu.gohome(); break;
claraluques 13:1670c34440a5 91 case 16: menu.limitepontos(); break;
claraluques 26:59081efdce79 92 case 17: menu.salvarprog(); break;
claraluques 27:83d2a710cc2f 93 case 18: menu.ctzhome(); break;
claraluques 27:83d2a710cc2f 94 case 19: menu.origem(); break;
claraluques 30:614dcbd74cdc 95 case 20: menu.nomeprog(); break;
claraluques 32:c293f89170b0 96 case 21: menu.mudar_nome(); break;
claraluques 5:30f5ffe0ea0b 97 }
claraluques 5:30f5ffe0ea0b 98 }
claraluques 11:6b7accf18fe2 99 }
claraluques 5:30f5ffe0ea0b 100
claraluques 11:6b7accf18fe2 101 //função interrupt botão enter
claraluques 11:6b7accf18fe2 102 void botenter_press(void){
claraluques 32:c293f89170b0 103 penter = bot_enter;
claraluques 32:c293f89170b0 104 bot_enter = !bot_enter;
claraluques 32:c293f89170b0 105 printf("enter high, timer reset FALL\n\r");
claraluques 32:c293f89170b0 106 timer.reset();
claraluques 32:c293f89170b0 107 timer.start();
claraluques 32:c293f89170b0 108 }
claraluques 9:86b5a317fcd4 109
claraluques 11:6b7accf18fe2 110 //função interrupt botão cima
claraluques 11:6b7accf18fe2 111 void botcima_press(void){
claraluques 32:c293f89170b0 112 pcima = bot_cima;
claraluques 32:c293f89170b0 113 bot_cima = !bot_cima;
claraluques 32:c293f89170b0 114 printf("cima high\n\r");
claraluques 32:c293f89170b0 115 }
wim 0:a75049de1a82 116
claraluques 5:30f5ffe0ea0b 117 //função interrupt botão baixo
claraluques 11:6b7accf18fe2 118 void botbaixo_press(void){
claraluques 32:c293f89170b0 119 pbaixo = bot_baixo;
claraluques 32:c293f89170b0 120 bot_baixo = !bot_baixo;
claraluques 32:c293f89170b0 121 printf("baixo high\n\r");
claraluques 32:c293f89170b0 122 }
claraluques 32:c293f89170b0 123
claraluques 32:c293f89170b0 124 //função para ler o timer
claraluques 32:c293f89170b0 125 void botenter_release(void){
claraluques 32:c293f89170b0 126 timer.stop();
claraluques 32:c293f89170b0 127 float t = timer.read();
claraluques 32:c293f89170b0 128 if (t>=2.0){
claraluques 32:c293f89170b0 129 sair = 1;
claraluques 32:c293f89170b0 130 }
claraluques 32:c293f89170b0 131 printf("%f,%d, time stop RISE\n\r", t, sair);
claraluques 32:c293f89170b0 132 }