Código para o menu no LCD

Dependencies:   mbed SDFileSystemSD TextLCD

Fork of TextLCD_HelloWorld2 by Wim Huiskamp

Committer:
lucasfontenla
Date:
Fri Jun 08 20:52:35 2018 +0000
Revision:
39:fbad08986621
Parent:
36:12d202855231
Child:
40:e70f811c69dc
Funfando sem bot?o de emerg?ncia;

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