5
5
#include " mbed.h"
6
6
7
7
// 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;
10
10
11
11
// Globals
12
12
DigitalOut alarm_out (D2, 0 );
@@ -19,9 +19,7 @@ InterruptIn sel(BUTTON2);
19
19
20
20
LowPowerTicker alarm_event;
21
21
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;
25
23
volatile uint8_t select_state = 0 ;
26
24
27
25
// Timer Callbacks
@@ -48,12 +46,10 @@ void set_time_leds(void)
48
46
void inc_delay (void )
49
47
{
50
48
if (select_state == 0 ) {
51
- delay += HOUR;
52
- hour_count++;
49
+ delay += hour_inc++;
53
50
hour_led = !hour_led;
54
51
} else {
55
- delay += MINUTE;
56
- min_count++;
52
+ delay =+ min_inc++;
57
53
min_led = !min_led;
58
54
}
59
55
}
@@ -92,19 +88,19 @@ int main()
92
88
93
89
// Sleep while waiting for user input to set the desired delay
94
90
while (select_state < 2 ) {
95
- ThisThread::sleep_for (10 );
91
+ ThisThread::sleep_for (10s );
96
92
}
97
93
98
94
// Once the delay has been input, blink back the configured hours and
99
95
// 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++) {
101
97
hour_led = !hour_led;
102
- ThisThread::sleep_for (250 );
98
+ ThisThread::sleep_for (250ms );
103
99
}
104
100
105
- for (uint8_t i = 0 ; i < min_count * 2 ; i++) {
101
+ for (uint8_t i = 0 ; i < min_inc. count () * 2 ; i++) {
106
102
min_led = !min_led;
107
- ThisThread::sleep_for (250 );
103
+ ThisThread::sleep_for (250ms );
108
104
}
109
105
110
106
// Attach the low power ticker with the configured alarm delay
0 commit comments