Skip to content

Commit f48c864

Browse files
author
Qinghao Shi
authored
Merge pull request #94 from maciejbocianski/move_pwm_examples
add PwmOut examples
2 parents 8509e3a + 2fd03d4 commit f48c864

File tree

6 files changed

+75
-0
lines changed

6 files changed

+75
-0
lines changed

APIs_Drivers/PwmOut_ex_1/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# PwmOut example
2+
3+
This example shows how to use PwmOut to modulate LED blinking.
4+
5+
**Note**: Set the cycle time. Then set the duty cycle using either a relative time period with the `write()` function or an absolute time period using the `pulsewidth()` function.

APIs_Drivers/PwmOut_ex_1/main.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (c) 2017-2020 Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include "mbed.h"
7+
8+
// Adjust pin name to your board specification.
9+
// You can use LED1/LED2/LED3/LED4 if any is connected to PWM capable pin,
10+
// or use any PWM capable pin, and see generated signal on logical analyzer.
11+
PwmOut led(LED2);
12+
13+
int main()
14+
{
15+
// specify period first, then everything else
16+
led.period(4.0f); // 4 second period
17+
led.write(0.50f); // 50% duty cycle
18+
while (1); // led flashing
19+
}

APIs_Drivers/PwmOut_ex_2/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# PwmOut example
2+
3+
This example shows how to use PwmOut to modulate LED blinking.
4+
5+
**Note**: Set the cycle time. Then set the duty cycle using either a relative time period with the `write()` function or an absolute time period using the `pulsewidth()` function.

APIs_Drivers/PwmOut_ex_2/main.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (c) 2017-2020 Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include "mbed.h"
7+
8+
// Adjust pin name to your board specification.
9+
// You can use LED1/LED2/LED3/LED4 if any is connected to PWM capable pin,
10+
// or use any PWM capable pin, and see generated signal on logical analyzer.
11+
PwmOut led(LED2);
12+
13+
int main()
14+
{
15+
// specify period first, then everything else
16+
led.period(4.0f); // 4 second period
17+
led.pulsewidth(2); // 2 second pulse (on)
18+
while (1); // led flashing
19+
}

APIs_Drivers/PwmOut_ex_3/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# PwmOut example
2+
3+
This example shows how to use PwmOut to modulate LED blinking.
4+
5+
**Note**: Set the cycle time. Then set the duty cycle using either a relative time period with the `write()` function or an absolute time period using the `pulsewidth()` function.
6+

APIs_Drivers/PwmOut_ex_3/main.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (c) 2014-2020 Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include "mbed.h"
7+
8+
// Adjust pin name to your board specification.
9+
// You can use LED1/LED2/LED3/LED4 if any is connected to PWM capable pin,
10+
// or use any PWM capable pin, and see generated signal on logical analyzer.
11+
PwmOut led(LED1);
12+
13+
int main()
14+
{
15+
// specify period first
16+
led.period(4.0f); // 4 second period
17+
led.write(0.50f); // 50% duty cycle, relative to period
18+
//led = 0.5f; // shorthand for led.write()
19+
//led.pulsewidth(2); // alternative to led.write, set duty cycle time in seconds
20+
while (1);
21+
}

0 commit comments

Comments
 (0)