-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
49 lines (38 loc) · 1005 Bytes
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* mbed Microcontroller Library
* Copyright (c) 2018-2019 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdio.h>
#include "mbed.h"
#include "mbed_stats.h"
#include "drivers/InterruptIn.h"
#include "drivers/PwmOut.h"
InterruptIn button(PTC6);
PwmOut led(PTC11);
void flip_pwm_state()
{
static bool pwm_state = true;
pwm_state = !pwm_state;
if (pwm_state) {
led.resume();
} else {
led.suspend();
}
}
int main(void)
{
// attach a handler to be executed on the button rising edge
button.rise(&flip_pwm_state);
// 4 second period
led.period(4.0f);
// 50% duty cycle, relative to period
led.write(0.50f);
while (1) {
ThisThread::sleep_for(1000);
mbed_stats_cpu_t stats;
mbed_stats_cpu_get(&stats);
printf("Uptime: %llu ", stats.uptime / 1000);
printf("Sleep time: %llu ", stats.sleep_time / 1000);
printf("Deep Sleep: %llu\n\r", stats.deep_sleep_time / 1000);
}
}