Código para o menu no LCD

Dependencies:   mbed SDFileSystemSD TextLCD

Fork of TextLCD_HelloWorld2 by Wim Huiskamp

Committer:
claraluques
Date:
Wed May 23 22:47:31 2018 +0000
Revision:
33:0149960e95c1
Parent:
32:c293f89170b0
Child:
34:7c7fac39a250
commit;

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