Código para o menu no LCD

Dependencies:   mbed SDFileSystemSD TextLCD

Fork of TextLCD_HelloWorld2 by Wim Huiskamp

Files at this revision

API Documentation at this revision

Comitter:
claraluques
Date:
Wed May 09 20:27:39 2018 +0000
Parent:
4:a3e4bb2053cb
Child:
6:24cbbdf2dac2
Commit message:
arrumar botoes

Changed in this revision

TextLCD.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/TextLCD.lib	Sun Mar 29 13:12:07 2015 +0000
+++ b/TextLCD.lib	Wed May 09 20:27:39 2018 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/wim/code/TextLCD/#ce348c002929
+http://mbed.org/users/wim/code/TextLCD/#4e70a08e8869
--- a/main.cpp	Sun Mar 29 13:12:07 2015 +0000
+++ b/main.cpp	Wed May 09 20:27:39 2018 +0000
@@ -1,76 +1,276 @@
-/* Hello World! for the TextLCD Enhanced Library*/
-
 #include "mbed.h"
 #include "TextLCD.h"
+ /*
+// Host PC Communication channels
+Serial pc(USBTX, USBRX); // tx, rx
  
+//I2C Communication
+I2C i2c_lcd(D14,D15); // SDA, SCL
+
+//Botão push
+InterruptIn botao(D7);
+
+//LCD instantiation 
+TextLCD_I2C lcd(&i2c_lcd, 0x7E, TextLCD::LCD20x4);         // I2C exp: I2C bus, PCF8574 Slaveaddress, LCD Type
+
+//variáveis int
+int colunas = lcd.columns();
+int linhas = lcd.rows();
+int c1 = 510000000;
+int pontosl = 10;
+int botpres;
+
+//variáveis float
+float coordx = 123;
+float coardy = 456;
+float coardz = 789;
+
+//funções
+void botao_press(void);
+void botao_solto(void);
+
+int main() { 
+    lcd.setBacklight(TextLCD::LightOn); //liga backlight
+    lcd.cls();        
+    lcd.printf("Certifique-se de que voce esta seguro para comecar");
+    
+    botao.rise(&botao_press);
+    botao.fall(&botao_solto); 
+    wait(2);
+    
+    while(1){        
+        while(1) {  
+           
+            
+            if (c1>500000000) {      
+                lcd.cls();
+                lcd.printf("FUNCAO JOG");
+                lcd.locate(0,1);
+                //lcd.printf("X: %.1f Y: %d.1 Z: %d.1", coordx, coordy, coordz);
+                lcd.locate(0,2);
+                lcd.printf("Aperte > ok p/ salvar o ponto %c", 0x3E);
+                //wait(0.5)
+                //lcd.printf("Aperte ok p/ salvar o ponto %c", 0xff);
+                InterruptIn botao(D7);
+                c1 = 0;
+                }
+                
+            c1++;
+            
+            if(botpres) { //se pressionado, aparece a tela de ponto salvo com contagem de pontos restantes
+                lcd.cls(); 
+                lcd.locate(0,0);
+                lcd.printf("Voce salvou um ponto");
+                lcd.locate(0,2);
+                pontosl--;
+                lcd.printf("Pontos livres: %d",pontosl);
+                wait(2);
+                c1=510000000;   
+                break;   
+                } 
+        } 
+    }
+} 
+
+void botao_press(void){
+          botpres = 1;
+          printf("pressionado\n\r");
+          }
+void botao_solto(void) {
+          botpres = 0;
+          printf("solto\n\r");
+          }
+               */
+               
+//#include mbed.h
+//#include "TextLCD.h"
+
 // Host PC Communication channels
 Serial pc(USBTX, USBRX); // tx, rx
  
-// I2C Communication
-I2C i2c_lcd(p9,p10); // SDA, SCL
-//I2C i2c_lcd(p28,p27); // SDA, SCL
- 
-// SPI Communication
-SPI spi_lcd(p5, NC, p7); // MOSI, MISO, SCLK
+//I2C Communication
+I2C i2c_lcd(D14,D15); // SDA, SCL
+
+//Botão push
+InterruptIn botao_enter(D13);
+InterruptIn botao_cima(D10);
+InterruptIn botao_baixo(D9);
+
+//LCD instantiation 
+TextLCD_I2C lcd(&i2c_lcd, 0x7E, TextLCD::LCD20x4);         // I2C exp: I2C bus, PCF8574 Slaveaddress, LCD Type
+
+//variáveis int
+//int max = 3;
+//int min = 0;
+int bot_enter;
+int bot_cima;
+int bot_baixo;
 
-// LCD instantiation 
-//TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD20x2);        // 4bit bus: rs, e, d4-d7
-TextLCD_I2C lcd(&i2c_lcd, 0x40, TextLCD::LCD20x4);                  // I2C exp: I2C bus, PCF8574 Slaveaddress, LCD Type
-//TextLCD_I2C lcd(&i2c_lcd, 0x42, TextLCD::LCD16x2, TextLCD::WS0010); // I2C exp: I2C bus, PCF8574 Slaveaddress, LCD Type, Ctrl Type
-//TextLCD_I2C lcd(&spi_lcd, p8, TextLCD::LCD24x4D);                   // I2C exp: SPI bus, CS pin, LCD Type
-//TextLCD_SPI_N lcd(&spi_lcd, p8, p9, TextLCD::LCD16x2, NC, TextLCD::ST7032_3V3); // SPI native: SPI bus, CS pin, RS pin, LCDType=LCD16x2, BL=NC, LCDTCtrl=ST7032
-//TextLCD_I2C_N lcd(&i2c_lcd, ST7032_SA, TextLCD::LCD16x2, NC, TextLCD::ST7032_3V3); // I2C native: I2C bus, slaveaddress, LCDType=LCD16x2, BL=NC, LCDTCtrl=ST7032 =Ok
-//TextLCD_I2C_N lcd(&i2c_lcd, SSD1803_SA1, TextLCD::LCD20x4D, NC, TextLCD::SSD1803_3V3); // I2C native: I2C bus, slaveaddress, LCDType=LCD20x4D, BL=NC, LCDTCtrl=SSD1803 =Ok
- 
-int main() {   
-  Timer t;
+//variáveis float
+float cx = 123;
+float cy = 456;
+float cz = 789;
+
+//funções interrupt
+void botenter_press(void);
+void botenter_solto(void);
 
-  pc.printf("TextLCD Enhanced Test. Columns=%d, Rows=%d\n\r", lcd.columns(), lcd.rows());
+void botcima_press(void);
+void botcima_solto(void);
+
+void botbaixo_press(void);
+void botbaixo_solto(void);
+
+//criar classe "menu" (funções das telas)
+class Menu{
+    public:
+    int linha;
+    int coluna;
+    int func;
     
-  for (int row=0; row<lcd.rows(); row++) {
-    int col=0;
-      
-    pc.printf("MemAddr(Col=%d, Row=%d)=0x%02X\n\r", col, row, lcd.getAddress(col, row));      
-//    lcd.putc('-');
-    lcd.putc('0' + row);      
-      
-    for (col=1; col<lcd.columns()-1; col++) {    
-      lcd.putc('*');
-    }
- 
-    pc.printf("MemAddr(Col=%d, Row=%d)=0x%02X\n\r", col, row, lcd.getAddress(col, row));      
-    lcd.putc('+');       
-  }    
-
-// Fill screen again and time it
-  t.start();
+    void movercursor(int min, int max){ //função para mover cursor de seleção
+        coluna = 0;
+        linha = min;
+        while (bot_enter==0){
+            if (bot_cima==1){
+                if (linha==min){
+                    linha=max;
+                    } 
+                else {
+                    linha--;
+                    }  
 
-  for (int row=0; row<lcd.rows(); row++) {
-    int col=0;
-      
-    lcd.putc('0' + row);      
-      
-    for (col=1; col<lcd.columns()-1; col++) {    
-      lcd.putc('*');
-    }
- 
-    lcd.putc('+');       
-  }    
-  t.stop();    
-  pc.printf("All my hard work took %f sec\r\n", t.read());          
+                }
+            if (bot_baixo==1){
+                if (linha==max){
+                    linha=min;
+                    }
+                else {
+                    linha++;
+                    }
+                }
+            lcd.locate(coluna, linha);
+            lcd.printf("%c", 0x3E);
+            printf("%d \n\r",linha);
+            printf("%d %d %d \n\r", bot_enter, bot_cima, bot_baixo);
+            wait(2);
+            }
+            //printf("%d \n\r",linha);            
+        }
+        
+                       
+    //func 0
+    void inicializar(){ //função tela incial de boas-vindas
+        lcd.cls();
+        lcd.locate(9,0);
+        lcd.printf("Ola!");
+        lcd.locate(0,1);
+        lcd.printf("Utilize seu EPI ao operar a maquina.");
+        wait(5);
+        func = 1;
+        }
+    
+    //func 1    
+    void menuprincipal(){ //função menu principal
+        lcd.cls();
+        lcd.locate(1,0);
+        lcd.printf("Modo JOG");
+        lcd.locate(1,1);
+        lcd.printf("Modo Automatico");
+        lcd.locate(1,2);
+        lcd.printf("Config");
+        movercursor(0,2);
+        if (bot_enter==1){
+            if (linha==0){
+                func = 2;
+                }
+            else if (linha==1) {
+                func = 3;
+                }
+            else if (linha==2) {
+                func = 4;
+                }
+            }
+        } 
+        Menu();
+};
 
-// Show cursor as blinking character
-   lcd.setCursor(TextLCD::CurOff_BlkOn);
- 
-// Set and show user defined characters. A maximum of 8 UDCs are supported by the HD44780.
-// They are defined by a 5x7 bitpattern. 
-  lcd.setUDC(0, (char *) udc_0);  // Show |>
-  lcd.putc(0);    
-  lcd.setUDC(1, (char *) udc_1);  // Show <|
-  lcd.putc(1);    
-    
-  pc.printf("Bye now\r\n");          
+Menu::Menu(){
+    func = 0;
 }
 
+Menu menu;  
 
+int main () {
+    lcd.setBacklight(TextLCD::LightOn); //liga backlight
+    lcd.setCursor(TextLCD::CurOff_BlkOff);
+    
+    botao_enter.rise(&botenter_press);
+    botao_enter.fall(&botenter_solto);
+    
+    botao_cima.rise(&botcima_press);
+    botao_cima.fall(&botcima_solto);
+    
+    botao_baixo.rise(&botbaixo_press);
+    botao_baixo.fall(&botbaixo_solto);
+    
+        
+    while(1){    
+        //printf("%d %d %d \n\r", bot_enter, bot_cima, bot_baixo);
+        switch(menu.func){
+            case 0: menu.inicializar(); break;
+            case 1: menu.menuprincipal(); break;
+            //case 2: menu.notReferenced(); break;
+            //case 3: menu.notReferenced(2); break;
+            //case 4: menu.notReferenced(3); break;
+            //case 5: menu.referencing(); break;
+            //case 6: menu.rootMenu(); break;
+            //case 7: menu.manualControl(); break;
+            //case 8: menu.positions(); break;
+            //case 9: menu.selectPos(); break;
+            //case 10: menu.selectPos(2); break;
+            //case 11: menu.selectPos(3); break;
+            //case 12: menu.run(); break;
+            }
+        } 
+    }     
+                
+                     
+        
+        
+        
+        
+//função interrupt botão enter
+        
+void botenter_press(void){
+          bot_enter = 1;
+          printf("enter high");
+          }
+void botenter_solto(void) {
+          bot_enter = 0;
+          printf("enter low");
+          }
+          
+//função interrupt botão cima
+          
+void botcima_press(void){
+          bot_cima = 1;
+          printf("cima high");
+          }
+void botcima_solto(void) {
+          bot_cima = 0;
+          printf("cima low");
+          }
 
+//função interrupt botão baixo          
+          
+void botbaixo_press(void){
+          bot_baixo = 1;
+          printf("baixo high");
+          }
+void botbaixo_solto(void) {
+          bot_baixo = 0;
+          printf("baixo low");
+          }
+        
+               
\ No newline at end of file