Time Machine
Dependencies: TextLCD mbed DebounceIn
main.cpp
- Committer:
- cicklaus
- Date:
- 2012-05-28
- Revision:
- 1:09c825e59a47
- Parent:
- 0:e37321609004
File content as of revision 1:09c825e59a47:
// Read from I2C slave at address 0x62
#include <iostream>
#include "mbed.h"
#include <math.h>
#include <string>
#define MESSAGE_BUFFER_SIZE 1024
#include "time.h"
#include <stdio.h>
#include <stdlib.h>
Serial pc(USBTX,USBRX);
char line= '\n';
char c;
char str[40];
char Hi;
int i;
struct tm t;
void message() //Get character (e.g. Printf the Words from serial)
{
strcpy (str,&Hi);
do {
c=pc.getc();
pc.putc (c);
strcat (str,&c);
}while (c != ' ');
}
void time_setup() {
pc.baud(9600);
pc.printf("SET TIME\n\r");
pc.printf("--------\n\r\n\r");
// get the current time from the terminal
do{
pc.printf("Enter current date and time:\n\r");
pc.printf("YYYY MM DD HH MM SS\n\r");
message();
t.tm_year = atoi (str);
message();
t.tm_mon = atoi (str);
message();
t.tm_mday= atoi (str);
message();
t.tm_hour = atoi (str);
message();
t.tm_min = atoi (str);
message();
t.tm_sec = atoi (str);
pc.printf("\n\r\n\r");
pc.printf("Is the time correct [y/n]\n\r");
c=pc.getc();
pc.printf("\n\r");
}while(c !='y');
// adjust for tm structure required values
t.tm_year = t.tm_year - 1900;
t.tm_mon = t.tm_mon - 1;
// set the time
set_time(mktime(&t));
// display the time
while(1) {
time_t seconds = time(NULL);
pc.printf("Time as a basic string = %s\n\r", ctime(&seconds));
wait(1);
}
}
int main()
{
time_setup();
}