![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
This program shows the on/off status of the switches in the LCD screen
main.cpp
- Committer:
- EduRemo
- Date:
- 2016-02-05
- Revision:
- 0:3e0cc153ba82
File content as of revision 0:3e0cc153ba82:
#include "mbed.h" #include "TextLCD.h" TextLCD lcd(PTC9, PTC8, PTA5, PTA4, PTA12, PTD4, TextLCD::LCD16x2); // rs, e, d4-d7 but could use DigitalIn sw1(PTD1); // Switch selected as input DigitalIn sw2(PTD3); DigitalIn sw3(PTD2); DigitalIn sw4(PTD0); int main() { lcd.cls(); // clear LCD screen lcd.printf(" Switch and LCD "); lcd.locate(0,1); // locate (column,row) lcd.printf("A= ,B= ,C= ,D= "); while (1){ if (sw1 == 1) {lcd.locate(2,1); lcd.printf("1"); } else {lcd.locate(2,1); lcd.printf("0");} if (sw2 == 1) {lcd.locate(6,1); lcd.printf("1"); } else {lcd.locate(6,1); lcd.printf("0");} if (sw3 == 1) {lcd.locate(10,1); lcd.printf("1"); } else {lcd.locate(10,1); lcd.printf("0");} if (sw4 == 1) {lcd.locate(14,1); lcd.printf("1"); } else {lcd.locate(14,1); lcd.printf("0");} } }