update clock
This commit is contained in:
parent
eb68b98cf5
commit
94f4b19460
|
@ -37,7 +37,7 @@
|
|||
#define PLATFORM_HAS_BATTERY 1
|
||||
|
||||
|
||||
#define LOOP_INTERVAL (30 * CLOCK_SECOND)
|
||||
#define LOOP_INTERVAL (1 * CLOCK_SECOND)
|
||||
|
||||
/* Save energy */
|
||||
//#define RDC_CONF_PT_YIELD_OFF
|
||||
|
|
|
@ -18,6 +18,13 @@ extern "C" {
|
|||
#include "cron.h"
|
||||
#include "time_resource.h"
|
||||
#include "jsonparse.h"
|
||||
#include "TM1637.h"
|
||||
|
||||
int8_t TimeDisp[] = {0x00,0x00,0x00,0x00};
|
||||
unsigned char ClockPoint = 1;
|
||||
unsigned char second;
|
||||
unsigned char minute = 0;
|
||||
unsigned char hour = 12;
|
||||
|
||||
extern resource_t res_led, res_battery, res_cputemp;
|
||||
|
||||
|
@ -25,12 +32,19 @@ uint8_t led_pin=4;
|
|||
uint8_t led_status;
|
||||
}
|
||||
|
||||
#define CLK 3//pins definitions for TM1637 and can be changed to other ports
|
||||
#define DIO 14
|
||||
TM1637 tm1637(CLK,DIO);
|
||||
|
||||
void setup (void)
|
||||
{
|
||||
// switch off the led
|
||||
pinMode(led_pin, OUTPUT);
|
||||
digitalWrite(led_pin, HIGH);
|
||||
led_status=0;
|
||||
// 4-Digit Display
|
||||
tm1637.set();
|
||||
tm1637.init();
|
||||
// init coap resourcen
|
||||
rest_init_engine ();
|
||||
#pragma GCC diagnostic ignored "-Wwrite-strings"
|
||||
|
@ -48,8 +62,35 @@ void setup (void)
|
|||
mcu_sleep_set(128);
|
||||
}
|
||||
|
||||
void loop (void)
|
||||
void TimeUpdate(void)
|
||||
{
|
||||
ClockPoint = (~ClockPoint) & 0x01;
|
||||
|
||||
second ++;
|
||||
if(second == 60)
|
||||
{
|
||||
minute ++;
|
||||
if(minute == 60)
|
||||
{
|
||||
hour ++;
|
||||
if(hour == 24)hour = 0;
|
||||
minute = 0;
|
||||
}
|
||||
second = 0;
|
||||
}
|
||||
|
||||
if(ClockPoint)tm1637.point(POINT_ON);
|
||||
else tm1637.point(POINT_OFF);
|
||||
|
||||
TimeDisp[0] = hour / 10;
|
||||
TimeDisp[1] = hour % 10;
|
||||
TimeDisp[2] = minute / 10;
|
||||
TimeDisp[3] = minute % 10;
|
||||
|
||||
}
|
||||
|
||||
void loop (void)
|
||||
{
|
||||
TimeUpdate();
|
||||
tm1637.display(TimeDisp);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue