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
Diff: main.cpp
- Revision:
- 4:0e5cead61795
- Parent:
- 3:b7614524bb8f
- Child:
- 5:6f2d3689b015
--- a/main.cpp Thu Mar 24 05:16:54 2016 +0000
+++ b/main.cpp Wed Mar 30 03:54:09 2016 +0000
@@ -4,7 +4,42 @@
#include "TextLCD.h"
TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD16x2); // rs, e, d4-d7
+Serial ftdi(USBTX, USBRX);
+DigitalIn button(p21);
+
+int count=0; // button count
+struct tm t; // current time will be stored here
+
+
int main() {
- lcd.printf("Hello World!\n");
+ lcd.printf("Welcome!\n");
+ ftdi.printf("Enter current date and time:\r\n");
+ ftdi.printf("YYYY MM DD HH MM SS[enter]\r\n\r\n");
+ 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);
+ 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);
+ ftdi.printf("\n\r");
+// ftdi.printf("-------------------------- \r\n");
+
+ t.tm_year = t.tm_year - 1900; // adjust for tm structure required values
+ t.tm_mon = t.tm_mon - 1;
+
+ set_time(mktime(&t)); // set the time
+
+
+ while(1)
+ {
+ time_t seconds = time(NULL);
+
+ if(button.read()==0) // if the button is pressed
+ {
+ while(button.read()==0); // wait until release
+ wait_ms(20); // button debounce
+ count++; // count up
+ ftdi.printf("Time: %s \rButton count: %d \r\n",ctime(&seconds),count); // send data to terminal
+ ftdi.printf("-------------------------- \r\n");
+ lcd.printf("Time: %s \rcount: %d \n\r",ctime(&seconds),count);
+// lcd.printf("-------------------------- \r\n");
+ }
+ }
}
