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.
Dependencies: Peripherals SD_Lib Time_Lib_v2 Year3_Version5 BMP280 LCDFunctions TextLCD BME280 Serial_Lib
Revision 5:60e116a1e913, committed 2018-11-19
- Comitter:
- emilytrembeth
- Date:
- Mon Nov 19 20:54:41 2018 +0000
- Parent:
- 4:da63962bc0f1
- Child:
- 6:2ef9c06ce506
- Commit message:
- x
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Nov 14 15:36:13 2018 +0000
+++ b/main.cpp Mon Nov 19 20:54:41 2018 +0000
@@ -4,13 +4,21 @@
#include "FATFileSystem.h"
#include "sample_hardware.hpp"
+#define Day 1
+#define Month 2
+#define Year 3
+#define Hour 4
+#define Minute 5
+#define Second 6
+
//Function declarations
void displayOnLcd();
void updateRealTimeClock(char *buffer);
void getLineFromSerial(char *keyBuffer, int bufferLength);
void displayMessageOnConsole();
-void Function1();
-void Function2();
+void SetingTimeWithButtons ();
+void FunctionSensor();
+void FunctionTime();
TextLCD lcd(D9, D8, D7, D6, D4, D2); // rs, e, d4-d7
SDBlockDevice sd(PB_5, D12, D13, D10); // mosi, miso, sclk, cs
@@ -21,6 +29,9 @@
Ticker ticker;
DigitalIn SWUser(USER_BUTTON);
Mutex date_mutex;
+int setting;
+int t;
+//InterruptIn SW1;
Thread t1;
Thread t2;
@@ -32,10 +43,10 @@
myled = !myled;
currentTime = time(NULL);
- strftime(lcdBuffer, 32, "%Y/%m/%d %H:%M:%S", localtime(¤tTime));
+ strftime(lcdBuffer, 32, "%d/%m/%Y %H:%M:%S", localtime(¤tTime));
//lcd.cls();
- //lcd.locate(0,0);
+// lcd.locate(0,0);
pc.printf("%s\n\r", lcdBuffer);
myled = !myled;
@@ -65,9 +76,9 @@
printf("\r\n");
// store number into time struct
- struct_time.tm_year = atoi(timeArray[0]) - 1900;
+ struct_time.tm_mday = atoi(timeArray[0]);
struct_time.tm_mon = atoi(timeArray[1]) - 1;
- struct_time.tm_mday = atoi(timeArray[2]);
+ struct_time.tm_year = atoi(timeArray[2]) - 1900;
struct_time.tm_hour = atoi(timeArray[3]);
struct_time.tm_min = atoi(timeArray[4]);
struct_time.tm_sec = atoi(timeArray[5]);
@@ -114,16 +125,133 @@
date_mutex.lock();
currentTime = time(NULL);
- strftime(lcdBuffer, 32, "%Y/%m/%d %H:%M:%S", localtime(¤tTime));
+ //strftime(lcdBuffer, 32, "%Y/%m/%d %H:%M:%S", localtime(¤tTime));
+ strftime(lcdBuffer, 32, "%d/%m/%Y %H:%M:%S", localtime(¤tTime));
printf("Current Time:%s\r\n", lcdBuffer);
- printf("Enter new Time (YYYY/mm/dd HH:MM:SS)\r\n");
+ printf("Enter new Time (dd/mm/YYYY HH:MM:SS)\r\n");
date_mutex.unlock();
}
+void SetingTimeWithButtons () {
+
+ int day = 0;
+ int month = 0;
+ int year = 2017;
+ int hour = 0;
+ int min = 0;
+ int sec = 0;
+
+ setting = Day;
+ t = 1;
+
+ while(t == 1) {
+ switch (setting) {
+ case Day:
+ if (SW1 == 1) {
+ wait(0.2);
+ day = day + 1;
+ lcd.cls();
+ lcd.locate(0,0);
+ lcd.printf("Day = %d\n\r", day);
+ }
+ if (SW2 == 1) {
+ setting = Month;
+ wait(0.5);
+ }
+ break;
+
+ case Month:
+ if (SW1 == 1) {
+ wait(0.2);
+ month = month + 1;
+ lcd.cls();
+ lcd.locate(0,0);
+ lcd.printf("Month = %d\n\r", month);
+ }
+ if (SW2 == 1) {
+ setting = Year;
+ wait(0.5);
+ }
+ break;
+
+ case Year:
+ if (SW1 == 1) {
+ wait(0.2);
+ year = year + 1;
+ lcd.cls();
+ lcd.locate(0,0);
+ lcd.printf("Year = %d\n\r", year);
+ }
+ if (SW2 == 1) {
+ setting = Hour;
+ wait(0.5);
+ }
+ break;
+
+ case Hour:
+ if (SW1 == 1) {
+ wait(0.2);
+ hour = hour + 1;
+ lcd.cls();
+ lcd.locate(0,0);
+ lcd.printf("Hour = %d\n\r", hour);
+ }
+ if (SW2 == 1) {
+ setting = Minute;
+ wait(0.5);
+ }
+ break;
+
+ case Minute:
+ if (SW1 == 1) {
+ wait(0.2);
+ min = min + 1;
+ lcd.cls();
+ lcd.locate(0,0);
+ lcd.printf("Minute = %d\n\r", min);
+ }
+ if (SW2 == 1) {
+ setting = Second;
+ wait(0.5);
+ }
+ break;
+
+ case Second:
+ if (SW1 == 1) {
+ wait(0.2);
+ sec = sec + 1;
+ lcd.cls();
+ lcd.locate(0,0);
+ lcd.printf("Second = %d\n\r", sec);
+ }
+ if (SW2 == 1) {
+ wait(0.5);
+ t = 0;
+ }
+ break;
+ }
+ }
+
+ struct tm struct_time;
+
+ //store number into time struct
+ struct_time.tm_year = year - 1900;
+ struct_time.tm_mon = month;
+ struct_time.tm_mday = day;
+ struct_time.tm_hour = hour;
+ struct_time.tm_min = min;
+ struct_time.tm_sec = sec;
+
+ // Coverting to time
+ time_t currentTime = mktime(&struct_time);
+ set_time(currentTime);
+
+ }
-void Function1()
+
+void FunctionSensor()
{
while (true) {
double temp = sensor.getTemperature();
@@ -140,12 +268,13 @@
}
}
-void Function2()
+void FunctionTime()
{
while (true) {
char lineBuffer[32];
char *pointer;
pointer = lineBuffer;
+ if (SW1 == 1) { //Set time on Putty
// show initial message on console
displayMessageOnConsole();
@@ -155,6 +284,12 @@
myled = !myled;
// update RTC based on input value
updateRealTimeClock(pointer);
+ }
+ if (SW2 == 1) { // Set time with Buttons
+ pc.printf("Ready");
+ wait(0.5);
+ SetingTimeWithButtons ();
+ }
while(true) {
displayOnLcd();
myled = !myled;
@@ -167,7 +302,7 @@
//Main thread
int main() {
- lcd.printf("Press a Switch\n\n");
+ lcd.printf("Select Time Option\n\n");
post();
@@ -188,9 +323,8 @@
}
// run threads
- t1.start(Function1);
- t2.start(Function2);
+ t1.start(FunctionSensor);
+ t2.start(FunctionTime);
}
-