Skip to content

add PwmOut examples #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions APIs_Drivers/PwmOut_ex_1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# PwmOut example

This example shows how to use PwmOut to modulate LED blinking.

**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.
19 changes: 19 additions & 0 deletions APIs_Drivers/PwmOut_ex_1/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2017-2020 Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*/

#include "mbed.h"

// Adjust pin name to your board specification.
// You can use LED1/LED2/LED3/LED4 if any is connected to PWM capable pin,
// or use any PWM capable pin, and see generated signal on logical analyzer.
PwmOut led(LED2);

int main()
{
// specify period first, then everything else
led.period(4.0f); // 4 second period
led.write(0.50f); // 50% duty cycle
while (1); // led flashing
}
5 changes: 5 additions & 0 deletions APIs_Drivers/PwmOut_ex_2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# PwmOut example

This example shows how to use PwmOut to modulate LED blinking.

**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.
19 changes: 19 additions & 0 deletions APIs_Drivers/PwmOut_ex_2/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2017-2020 Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*/

#include "mbed.h"

// Adjust pin name to your board specification.
// You can use LED1/LED2/LED3/LED4 if any is connected to PWM capable pin,
// or use any PWM capable pin, and see generated signal on logical analyzer.
PwmOut led(LED2);

int main()
{
// specify period first, then everything else
led.period(4.0f); // 4 second period
led.pulsewidth(2); // 2 second pulse (on)
while (1); // led flashing
}
6 changes: 6 additions & 0 deletions APIs_Drivers/PwmOut_ex_3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# PwmOut example

This example shows how to use PwmOut to modulate LED blinking.

**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.

21 changes: 21 additions & 0 deletions APIs_Drivers/PwmOut_ex_3/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2014-2020 Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*/

#include "mbed.h"

// Adjust pin name to your board specification.
// You can use LED1/LED2/LED3/LED4 if any is connected to PWM capable pin,
// or use any PWM capable pin, and see generated signal on logical analyzer.
PwmOut led(LED1);

int main()
{
// specify period first
led.period(4.0f); // 4 second period
led.write(0.50f); // 50% duty cycle, relative to period
//led = 0.5f; // shorthand for led.write()
//led.pulsewidth(2); // alternative to led.write, set duty cycle time in seconds
while (1);
}