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.
Fork of TextLCD_HelloWorld by
main.cpp@4:0e5cead61795, 2016-03-30 (annotated)
- Committer:
- amrita_arm19
- Date:
- Wed Mar 30 03:54:09 2016 +0000
- Revision:
- 4:0e5cead61795
- Parent:
- 3:b7614524bb8f
- Child:
- 5:6f2d3689b015
Working;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| simon | 1:7418a52375a0 | 1 | // Hello World! for the TextLCD |
| simon | 1:7418a52375a0 | 2 | |
| simon | 0:334327d1a416 | 3 | #include "mbed.h" |
| simon | 0:334327d1a416 | 4 | #include "TextLCD.h" |
| simon | 0:334327d1a416 | 5 | |
| amrita_arm19 | 3:b7614524bb8f | 6 | TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD16x2); // rs, e, d4-d7 |
| amrita_arm19 | 4:0e5cead61795 | 7 | Serial ftdi(USBTX, USBRX); |
| amrita_arm19 | 4:0e5cead61795 | 8 | DigitalIn button(p21); |
| amrita_arm19 | 4:0e5cead61795 | 9 | |
| amrita_arm19 | 4:0e5cead61795 | 10 | int count=0; // button count |
| amrita_arm19 | 4:0e5cead61795 | 11 | struct tm t; // current time will be stored here |
| amrita_arm19 | 4:0e5cead61795 | 12 | |
| amrita_arm19 | 4:0e5cead61795 | 13 | |
| simon | 0:334327d1a416 | 14 | |
| simon | 0:334327d1a416 | 15 | int main() { |
| amrita_arm19 | 4:0e5cead61795 | 16 | lcd.printf("Welcome!\n"); |
| amrita_arm19 | 4:0e5cead61795 | 17 | ftdi.printf("Enter current date and time:\r\n"); |
| amrita_arm19 | 4:0e5cead61795 | 18 | ftdi.printf("YYYY MM DD HH MM SS[enter]\r\n\r\n"); |
| amrita_arm19 | 4:0e5cead61795 | 19 | ftdi.scanf("%d %d %d %d %d %d", &t.tm_year, &t.tm_mon, &t.tm_mday, &t.tm_hour, &t.tm_min, &t.tm_sec); |
| amrita_arm19 | 4:0e5cead61795 | 20 | ftdi.printf("%d %d %d %d %d %d", t.tm_year, t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec); |
| amrita_arm19 | 4:0e5cead61795 | 21 | ftdi.printf("\n\r"); |
| amrita_arm19 | 4:0e5cead61795 | 22 | // ftdi.printf("-------------------------- \r\n"); |
| amrita_arm19 | 4:0e5cead61795 | 23 | |
| amrita_arm19 | 4:0e5cead61795 | 24 | t.tm_year = t.tm_year - 1900; // adjust for tm structure required values |
| amrita_arm19 | 4:0e5cead61795 | 25 | t.tm_mon = t.tm_mon - 1; |
| amrita_arm19 | 4:0e5cead61795 | 26 | |
| amrita_arm19 | 4:0e5cead61795 | 27 | set_time(mktime(&t)); // set the time |
| amrita_arm19 | 4:0e5cead61795 | 28 | |
| amrita_arm19 | 4:0e5cead61795 | 29 | |
| amrita_arm19 | 4:0e5cead61795 | 30 | while(1) |
| amrita_arm19 | 4:0e5cead61795 | 31 | { |
| amrita_arm19 | 4:0e5cead61795 | 32 | time_t seconds = time(NULL); |
| amrita_arm19 | 4:0e5cead61795 | 33 | |
| amrita_arm19 | 4:0e5cead61795 | 34 | if(button.read()==0) // if the button is pressed |
| amrita_arm19 | 4:0e5cead61795 | 35 | { |
| amrita_arm19 | 4:0e5cead61795 | 36 | while(button.read()==0); // wait until release |
| amrita_arm19 | 4:0e5cead61795 | 37 | wait_ms(20); // button debounce |
| amrita_arm19 | 4:0e5cead61795 | 38 | count++; // count up |
| amrita_arm19 | 4:0e5cead61795 | 39 | ftdi.printf("Time: %s \rButton count: %d \r\n",ctime(&seconds),count); // send data to terminal |
| amrita_arm19 | 4:0e5cead61795 | 40 | ftdi.printf("-------------------------- \r\n"); |
| amrita_arm19 | 4:0e5cead61795 | 41 | lcd.printf("Time: %s \rcount: %d \n\r",ctime(&seconds),count); |
| amrita_arm19 | 4:0e5cead61795 | 42 | // lcd.printf("-------------------------- \r\n"); |
| amrita_arm19 | 4:0e5cead61795 | 43 | } |
| amrita_arm19 | 4:0e5cead61795 | 44 | } |
| simon | 0:334327d1a416 | 45 | } |
