Demo for button and backlight use with Arduino LCD Keypad Shield (HD44780) and similar 16x2 hardware clones. Press 'Up' or 'Down' button to ON or OFF backlight. Build and test with STM32 Nucleo F411RE.

Dependencies:   TextLCD mbed

Files at this revision

API Documentation at this revision

Comitter:
werwolf_lg
Date:
Wed Dec 23 16:58:19 2015 +0000
Commit message:
First version demo for Arduino LCD Keypad Shield and STM32 Nucleo

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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 8f6ff5bb5a2d TextLCD.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Wed Dec 23 16:58:19 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/TextLCD/#308d188a2d3a
diff -r 000000000000 -r 8f6ff5bb5a2d main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Dec 23 16:58:19 2015 +0000
@@ -0,0 +1,57 @@
+#include "mbed.h"
+#include "TextLCD.h"
+
+Serial pc(SERIAL_TX, SERIAL_RX); 
+AnalogIn button(A0);    // Init button (SELECT, LEFT, UP, DOWN, RIGHT)
+// LCD (RS, E, D4, D5, D6, D7);
+TextLCD lcd(D8, D9, D4, D5, D6, D7);
+PwmOut backlight(D10);  // Backlight LCD
+DigitalOut led(LED1);
+
+int main() {
+    
+    // Set backlight period and duty cycle 
+    backlight.period(0.002);
+    backlight = 1;
+    
+    
+    lcd.cls();                      // Clear LCD
+    lcd.locate(1,0);                // Set locate (1 row, 2 column)
+    lcd.printf("LCD Key Shield");
+    wait(1);
+    
+    int meas;
+    
+    while(1) {
+        led = (led == 1) ? 0 : 1;
+
+        meas = button.read() * 1000; // Read the analog input value (value from 0.0 to 1.0) and convert to int value (from 0 to 1000)
+        
+        lcd.cls();
+        lcd.locate(0,0);
+        lcd.printf("Press button");
+        lcd.locate(0,1);
+        
+        if (meas < 50) { 
+            lcd.printf("BUTTON: Right ");
+            backlight = 0.5;        // Set 50% backlight 
+        }
+        else if (meas < 210) { 
+            lcd.printf("BUTTON: Up");
+            backlight = 1;          // Power ON backlight
+        } 
+        else if (meas < 460){ 
+            lcd.printf("BUTTON: Down");
+            backlight = 0;          // Power OFF backlight
+        } 
+        else if (meas < 720){ 
+            lcd.printf("BUTTON: Left"); 
+        } 
+        else if (meas > 950){ 
+            lcd.printf("BUTTON: Select");
+        }
+        pc.printf("BUTTON: %4d\n", meas);
+        
+        wait(0.1);
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r 8f6ff5bb5a2d mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Dec 23 16:58:19 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/4336505e4b1c
\ No newline at end of file