3 ms·
While we're talking LEDs: https://gist.github.com/phkahler/1ddddb79fc57072c4269fdd6716bfb72 https://gist.github.com/phkahler/1ddddb79fc57072c4269fdd6716... In
by phkahler 5y ago
While we're talking LEDs:
https://gist.github.com/phkahler/1ddddb79fc57072c4269fdd6716bfb72 https://gist.github.com/phkahler/1ddddb79fc57072c4269fdd6716...
In 6 lines we smoothly blink (fade on and off) an LED on a regular GPIO pin. Uses some fixed-point math and pulse-density modulation.
- qazxcvbnmlp 5y agoChances are, if you understand your embedded system well enough to ‘call the function every 1ms or so’ consistently and reliably the additional challenge of fading the led will be minimal. The hard part about fading leds on an embedded system is usually the timing rather than the math.
- phkahler 5y ago>> The hard part about fading leds on an embedded system is usually the timing rather than the math. I do a lot of power electronics work where we have an interrupt every PWM cycle (in the kHz range). In that case the PWMs are already used for critical things and the timing is already solid, so this really is a drop-in blinker/fader. Of course lots of applications have a spare PWM they can utilize for changing brightness of an LED, but the setup is still probably more than the code here ;-)