Shylaja Mohanraj / Mbed 2 deprecated BlackBox

Dependencies:   TextLCD mbed

Fork of TextLCD_HelloWorld by Simon Ford

main.cpp

Committer:
amrita_arm19
Date:
2016-03-30
Revision:
4:0e5cead61795
Parent:
3:b7614524bb8f
Child:
5:6f2d3689b015

File content as of revision 4:0e5cead61795:

// Hello World! for the TextLCD

#include "mbed.h"
#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("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");
            }  
        }
}