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