55#include " mbed.h"
66
77// Time constants in seconds
8- # define HOUR 60 * 60
9- # define MINUTE 60
8+ std::chrono::hours hour_inc;
9+ std::chrono::minutes min_inc;
1010
1111// Globals
1212DigitalOut alarm_out (D2, 0 );
@@ -19,9 +19,7 @@ InterruptIn sel(BUTTON2);
1919
2020LowPowerTicker alarm_event;
2121
22- volatile uint64_t delay = 0 ;
23- volatile uint8_t hour_count = 0 ;
24- volatile uint8_t min_count = 0 ;
22+ std::chrono::microseconds delay;
2523volatile uint8_t select_state = 0 ;
2624
2725// Timer Callbacks
@@ -48,12 +46,10 @@ void set_time_leds(void)
4846void inc_delay (void )
4947{
5048 if (select_state == 0 ) {
51- delay += HOUR;
52- hour_count++;
49+ delay += hour_inc++;
5350 hour_led = !hour_led;
5451 } else {
55- delay += MINUTE;
56- min_count++;
52+ delay =+ min_inc++;
5753 min_led = !min_led;
5854 }
5955}
@@ -92,19 +88,19 @@ int main()
9288
9389 // Sleep while waiting for user input to set the desired delay
9490 while (select_state < 2 ) {
95- ThisThread::sleep_for (10 );
91+ ThisThread::sleep_for (10s );
9692 }
9793
9894 // Once the delay has been input, blink back the configured hours and
9995 // minutes selected
100- for (uint8_t i = 0 ; i < hour_count * 2 ; i++) {
96+ for (uint8_t i = 0 ; i < hour_inc. count () * 2 ; i++) {
10197 hour_led = !hour_led;
102- ThisThread::sleep_for (250 );
98+ ThisThread::sleep_for (250ms );
10399 }
104100
105- for (uint8_t i = 0 ; i < min_count * 2 ; i++) {
101+ for (uint8_t i = 0 ; i < min_inc. count () * 2 ; i++) {
106102 min_led = !min_led;
107- ThisThread::sleep_for (250 );
103+ ThisThread::sleep_for (250ms );
108104 }
109105
110106 // Attach the low power ticker with the configured alarm delay
0 commit comments