Last active
July 15, 2017 15:07
-
-
Save Ryanhu1015/f330ecb3d0b5f85d6be6da0aa1e86234 to your computer and use it in GitHub Desktop.
interrupt_countingTime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern "C" | |
{ | |
#include "user_interface.h" | |
} | |
os_timer_t myTimer; | |
void user_init(void) // the function will be set in setup to trigger the ISR function | |
{ | |
os_timer_setfn(&myTimer, timerCallback, NULL); | |
os_timer_arm(&myTimer, 1, true);//call interrupt function every 1 millisec | |
} | |
void setup() | |
{ | |
//skip the part above | |
user_init(); | |
} | |
void loop() | |
{ | |
//release main loop to let it be blank | |
} | |
void timerCallback(void *pArg) | |
{ | |
timeNow++; | |
if (timeNow - timeLast == 1000)//go in the if statement every 1 sec | |
{ | |
timeLast = timeNow; | |
seconds++; | |
if (initialSecond) | |
{ | |
seconds = initialSecond; | |
initialSecond = 0; | |
} | |
//-------the section for "seconds"-------- | |
if (seconds == 60) | |
{ | |
seconds = 0; | |
minutes = minutes + 1; | |
} | |
//-------the section for "minutes"-------- | |
if (minutes == 60) | |
{ | |
minutes = 0; | |
hours = hours + 1; | |
} | |
//-------the section for "hours"-------- | |
if (hours == 24) | |
{ | |
hours = 0; | |
days = days + 1; | |
} | |
time_first = seconds % 10; | |
time_second = seconds / 10; | |
time_third = minutes % 10; | |
time_forth = minutes / 10; | |
time_fifth = hours % 10; | |
time_sixth = hours / 10; | |
sendDataToColorduino();// function to send data to show on those colorduino board | |
calibrateTime();// function to calibrate Time through getting ntp server time again at every specific time i set | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment