Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 #include "TextLCD.h" 00003 00004 Serial pc(SERIAL_TX, SERIAL_RX); 00005 AnalogIn button(A0); // Init button (SELECT, LEFT, UP, DOWN, RIGHT) 00006 // LCD (RS, E, D4, D5, D6, D7); 00007 TextLCD lcd(D8, D9, D4, D5, D6, D7); 00008 //PwmOut backlight(D10); // Backlight LCD 00009 DigitalOut led(LED1); 00010 00011 00012 int main() { 00013 00014 // Set backlight period and duty cycle 00015 //backlight.period(0.002); 00016 //backlight = 1; 00017 00018 00019 lcd.cls(); // Clear LCD 00020 lcd.locate(1,0); // Set locate (1 row, 2 column) 00021 lcd.printf("LCD Key Shield"); 00022 wait(1); 00023 00024 int meas; 00025 00026 while(1) { 00027 led = (led == 1) ? 0 : 1; 00028 00029 meas = button * 1000; // Read the analog input value (value from 0.0 to 1.0) and convert to int value (from 0 to 1000) 00030 00031 lcd.cls(); 00032 lcd.locate(0,0); 00033 lcd.printf("Press button"); 00034 lcd.locate(0,1); 00035 00036 if (meas < 50) { 00037 lcd.printf("BUTTON: Right "); 00038 //backlight = 0.5; // Set 50% backlight 00039 } 00040 else if (meas < 250) { 00041 lcd.printf("BUTTON: Up"); 00042 //backlight = 1; // Power ON backlight 00043 } 00044 else if (meas < 530){ 00045 lcd.printf("BUTTON: Down"); 00046 //backlight = 0; // Power OFF backlight 00047 } 00048 else if (meas < 780&&meas>735){ 00049 lcd.printf("BUTTON: Left"); 00050 } 00051 else if (meas > 950){ 00052 lcd.printf("BUTTON: Select"); 00053 } 00054 pc.printf("BUTTON: %4d\n", meas); 00055 00056 wait(0.1); 00057 } 00058 }
Generated on Wed Jul 13 2022 16:06:39 by
1.7.2