Menu para a IHM

Dependencies:   TextLCD mbed

Fork of TextLCD_HelloWorld2 by Wim Huiskamp

Revision:
5:9936706721a8
Parent:
4:a3e4bb2053cb
Child:
6:49a35089f51b
--- a/main.cpp	Sun Mar 29 13:12:07 2015 +0000
+++ b/main.cpp	Mon May 07 17:58:59 2018 +0000
@@ -2,74 +2,95 @@
 
 #include "mbed.h"
 #include "TextLCD.h"
+//#include "TextLCDScroll.h"
+InterruptIn button1(D5);
+InterruptIn button2(D4);
+
+DigitalOut led(LED2);
  
 // 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 i2c_lcd(D14,D15); // SDA, SCL
+
+
+TextLCD_I2C lcd(&i2c_lcd, 0x7E, TextLCD::LCD20x4);                  // I2C exp: I2C bus, PCF8574 Slaveaddress, LCD Type
+
+bool flag_sim=0, flag_nao=0; 
+bool flag_sele=0, flag_cancel=0;
 
-// 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
- 
+ void sim()
+    {
+        flag_sim=1;
+    }
+ void nao()
+    {
+        flag_nao=1;
+    }
+ void sele()
+     {
+        flag_sele=1   ;
+      }
+  void cancel()
+    { 
+        flag_cancel=1   ;
+     } 
 int main() {   
-  Timer t;
 
-  pc.printf("TextLCD Enhanced Test. Columns=%d, Rows=%d\n\r", lcd.columns(), lcd.rows());
-    
-  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('*');
-    }
+    lcd.setBacklight(TextLCD::LightOn);
+    lcd.setCursor(TextLCD::CurOff_BlkOn);
  
-    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();
-
-  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.setAddress(0,0);
+    lcd.printf("Selecionar ponto? ");
+    lcd.setAddress(0,1);
+    lcd.printf("1-Sim");
+    lcd.setAddress(7,1);
+    lcd.printf("2-Nao");
+    
+    button1.fall(&sim);
+    button2.fall(&nao);
+        
+    while(1)
+    {
+        
+        if(flag_sim==1)
+        {
+            lcd.cls();
+            lcd.setAddress(0,0);
+            lcd.printf("selecione o ponto");
+            lcd.setCursor(TextLCD::CurOff_BlkOff);
+            printf("selecione o ponto\r\n");
+            /* button1.fall(&sele);
+             button2.fall(&cancel);                    
+                if (flag_sele==1)
+                {
+                    lcd.cls();
+                    lcd.setAddress(0,0);           
+                    lcd.printf("Mais algum ponto?");
+                    lcd.setAddress(2,1);
+                    lcd.printf("1-Sim");
+                    lcd.setAddress(2,7);
+                    lcd.printf("2-Nao");
+                    flag_sele=0;
+                    }*/
+            flag_sim=0;
+            
+        }
+        
+        if(flag_nao==1)
+        {
+            lcd.cls();
+            lcd.setAddress(0,0);
+            lcd.printf("operacao cancelada") ;
+            printf("operacao cancelada\r\n");
+            flag_nao=0; 
+        }
+        
+        led=!led;
+        wait(0.1);
     }
- 
-    lcd.putc('+');       
-  }    
-  t.stop();    
-  pc.printf("All my hard work took %f sec\r\n", t.read());          
-
-// 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");          
 }