Very simple class to give slow speed PWM using timers and digital out.
Example use...
#include "SlowPWM.h" SlowPWM MyTimer1(LED1); SlowPWM MyTimer2(LED2); SlowPWM MyTimer3(LED3); main() { MyTimer1.setPeriod(4); MyTimer1.setHighTime(2); MyTimer1.start(); MyTimer2.setPeriod(2); MyTimer2.setHighTime(1.5); MyTimer2.start(); MyTimer3.setPeriod(3.8); MyTimer3.setHighTime(1.5); MyTimer3.start(); while(true) { wait(1); } }
Diff: SlowPWM.h
- Revision:
- 3:3f7eb3ad23d4
- Parent:
- 2:c90e2d2f52aa
--- a/SlowPWM.h Fri Jun 21 09:33:26 2019 +0000 +++ b/SlowPWM.h Fri Jun 21 09:45:08 2019 +0000 @@ -17,13 +17,13 @@ // constructor that also starts things running SlowPWM( const PinName pin, const float period, const float highTime); -// set the period +/// set the period void setPeriod(const float period); -// set the on time per cycle +/// set the on time per cycle. If 0 or the period or longer timers are stopped and output set perminently void setHighTime(const float highTime); -// set the on time per cycle as a fraction +// set the on time per cycle as a fraction of the period. void setDutyCycle(const float cycle); // stop things.