Skip to content

Commit 991e509

Browse files
add LowPowerTicker examples (#79)
1 parent 7810387 commit 991e509

File tree

6 files changed

+79
-0
lines changed

6 files changed

+79
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# LowpowerTicker example
2+
3+
This example shows how to use the LowpowerTicker to cause periodic events, like blinking an LED on and Off at a certain rate. In this example LED1 is controlled by the main while loop, while LED2 is controlled by the Ticker callback function.
4+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2020 Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include "mbed.h"
7+
8+
LowPowerTicker flipper;
9+
DigitalOut led1(LED1);
10+
11+
void flip()
12+
{
13+
led1 = !led1;
14+
}
15+
16+
int main()
17+
{
18+
led1 = 1;
19+
flipper.attach(&flip, 2.0); // the address of the function to be attached (flip) and the interval (2 seconds)
20+
21+
while (1) {
22+
ThisThread::sleep_for(200);
23+
}
24+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# LowpowerTimout example
2+
3+
This example shows how to use a LowpowerTimout to schedule delayed events. The LowPowerTimeout API is a countdown timer that triggers a callback function when the timer runs out. The LowPowerTimeout interface can be though of as a one shot LowPowerTicker.
4+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (c) 2020 Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include "mbed.h"
7+
8+
LowPowerTimeout flipper;
9+
DigitalOut led1(LED1);
10+
DigitalOut led2(LED2);
11+
12+
void flip()
13+
{
14+
led2 = !led2;
15+
}
16+
17+
int main()
18+
{
19+
led2 = 1;
20+
flipper.attach(&flip, 2.0); // setup flipper to call flip after 2 seconds
21+
22+
// spin in a main loop. flipper will interrupt it to call flip
23+
while (1) {
24+
led1 = !led1;
25+
ThisThread::sleep_for(200);
26+
}
27+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# LowpowerTimer example
2+
3+
This example shows how to use a LowpowerTimer to measure time. The time will be the amount of time between when the start() and stop() functions are run. The Timer class counts from 0 up.
4+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (c) 2020 Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include "mbed.h"
7+
8+
LowPowerTimer t;
9+
10+
int main()
11+
{
12+
t.start();
13+
printf("Hello World!\n");
14+
t.stop();
15+
printf("The time taken was %f seconds\n", t.read());
16+
}

0 commit comments

Comments
 (0)