timer

Dependencies:   4DGL-uLCD-SE mbed

Fork of time_HelloWorld by mbed official

Committer:
lzzcd001
Date:
Sun Mar 08 18:02:09 2015 +0000
Revision:
2:d0c79e7761e2
Parent:
0:b3b93997a0a6
timer

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:b3b93997a0a6 1 #include "mbed.h"
lzzcd001 2:d0c79e7761e2 2 #include "uLCD_4DGL.h"
lzzcd001 2:d0c79e7761e2 3 // uncomment this line to enable the uLCD for Part 4 of the lab
lzzcd001 2:d0c79e7761e2 4 uLCD_4DGL lcd(p28, p27, p30);
lzzcd001 2:d0c79e7761e2 5 Serial pc(USBTX, USBRX);
lzzcd001 2:d0c79e7761e2 6
lzzcd001 2:d0c79e7761e2 7 void setup()
lzzcd001 2:d0c79e7761e2 8 {
lzzcd001 2:d0c79e7761e2 9 lcd.baudrate(3000000);
lzzcd001 2:d0c79e7761e2 10 lcd.background_color(0);
lzzcd001 2:d0c79e7761e2 11 lcd.cls();
lzzcd001 2:d0c79e7761e2 12
lzzcd001 2:d0c79e7761e2 13 //lcd.printf("Initializing...");
lzzcd001 2:d0c79e7761e2 14
lzzcd001 2:d0c79e7761e2 15 //Make sure communication is working
lzzcd001 2:d0c79e7761e2 16 }
mbed_official 0:b3b93997a0a6 17
mbed_official 0:b3b93997a0a6 18 int main() {
mbed_official 0:b3b93997a0a6 19 set_time(1256729737); // Set RTC time to Wed, 28 Oct 2009 11:35:37
lzzcd001 2:d0c79e7761e2 20 setup();
lzzcd001 2:d0c79e7761e2 21
mbed_official 0:b3b93997a0a6 22 while (true) {
mbed_official 0:b3b93997a0a6 23 time_t seconds = time(NULL);
mbed_official 0:b3b93997a0a6 24
mbed_official 0:b3b93997a0a6 25 printf("Time as seconds since January 1, 1970 = %d\n", seconds);
mbed_official 0:b3b93997a0a6 26
mbed_official 0:b3b93997a0a6 27 printf("Time as a basic string = %s", ctime(&seconds));
lzzcd001 2:d0c79e7761e2 28
lzzcd001 2:d0c79e7761e2 29 lcd.cls();
mbed_official 0:b3b93997a0a6 30 char buffer[32];
mbed_official 0:b3b93997a0a6 31 strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds));
mbed_official 0:b3b93997a0a6 32 printf("Time as a custom formatted string = %s", buffer);
lzzcd001 2:d0c79e7761e2 33 //lcd.set_font(FONT_12X16);
lzzcd001 2:d0c79e7761e2 34 //lcd.text_mode(OPAQUE);
lzzcd001 2:d0c79e7761e2 35 //lcd.locate(0,0);
lzzcd001 2:d0c79e7761e2 36 //lcd.printf(buffer);
lzzcd001 2:d0c79e7761e2 37 //lcd.text_string(buffer,2,2,FONT_12X16, RED);
lzzcd001 2:d0c79e7761e2 38 //lcd.text_string("This is a test of string", 1, 4, FONT_12X16, BLUE);
lzzcd001 2:d0c79e7761e2 39 lcd.text_width(3); //4X size text
lzzcd001 2:d0c79e7761e2 40 lcd.text_height(3);
lzzcd001 2:d0c79e7761e2 41 lcd.color(RED);
lzzcd001 2:d0c79e7761e2 42 //lcd.set_font(MEDIAFONT);
lzzcd001 2:d0c79e7761e2 43 //lcd.text_bold(ON);
lzzcd001 2:d0c79e7761e2 44 lcd.locate(0,2);
lzzcd001 2:d0c79e7761e2 45 lcd.printf(buffer);
lzzcd001 2:d0c79e7761e2 46 //lcd.text_char('B', 4, 4, RED);
lzzcd001 2:d0c79e7761e2 47 //lcd.text_char('I',10, 8, RED);
lzzcd001 2:d0c79e7761e2 48 //lcd.text_char('G',11, 8, RED);
mbed_official 0:b3b93997a0a6 49 wait(1);
mbed_official 0:b3b93997a0a6 50 }
mbed_official 0:b3b93997a0a6 51 }