lcd clock

Dependencies:   NTPClient_NetServices mbed 4DGL-uLCD-SE EthernetNetIf

Internet_LCD_Clock.cpp

Committer:
emilywilson
Date:
2020-02-06
Revision:
1:9da7a9089f12
Parent:
0:da7f4b6d2b7c

File content as of revision 1:9da7a9089f12:

#include "mbed.h"
#include "EthernetNetIf.h"
#include "NTPClient.h"
#include "uLCD_4DGL.h"
// Internet of Things clock example: LCD time is set via internet NTP time server
EthernetNetIf eth;
NTPClient ntp;
uLCD_4DGL lcd(p28,p27,p30); // mosi, sclk, cs, rst, type

int main() {
//system time structure
    time_t ctTime;
    char *time_str;
    //clear LCD
    // lcd.printf prints to LCD display;
    lcd.printf("Get IP addr...");
    EthernetErr ethErr = eth.setup();
    //Get an Internet IP address using DHCP
    if (ethErr) {
        //error or timeout getting an IP address
        lcd.printf("Net Error %d",ethErr);
        return -1;
    }
    lcd.printf("Reading Time...");
    //specify time server URL
    Host server(IpAddr(), 123, "0.north-america.pool.ntp.org");
    //Read time from server
    ntp.setTime(server);
    lcd.printf("Time set");
    //Delay for human time to read LCD display
    wait(1);
    while (1) {
        // loop and periodically update the LCD's time display
        lcd.cls();
        ctTime = time(NULL);
        lcd.printf("UTC:");
        time_str = ctime(&ctTime);
        time_str[strlen(time_str)-1] = 0;
        lcd.printf("%s", time_str);
        wait(1);
    }
}