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