I have set up a very simple test program to blink an builtin LED using PWM. Following the mbed example and setting the period to 4 seconds (0.25 Hz) and duty cycle to 0.5, the expected behaviour is for the LED to be on for 2 seconds and off for 2 seconds. However, the actual behaviour is that the LED flashes extremely quickly (almost imperceptable to the eye).
#include "mbed.h"
mbed::PwmOut ledPin = mbed::PwmOut(P0_13); //builtin led pin
void setup() {
ledPin.period(4.0f);
ledPin.write(0.0f);
}
void loop() {
// put your main code here, to run repeatedly:
ledPin.write(0.5f);
}
I have tried adding delay()
and wait_ns()
with different times in the main loop, tried having the main loop empty and setting the duty cycle in the setup()
function as well as changing the period to larger numbers just in case it was in milliseconds all to no avail. Not quite sure what I'm missing from this extremely simple example.
PwmOut ledPin(P0_13)
. For the setup(), set the duty cycle to 50% withledPin.write(0.5f);
, and delete the code within the loop() as itself is already awhile(1)
loop.