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:
- 1:386d04fe1e37
- Parent:
- 0:76861123625b
- Child:
- 2:c90e2d2f52aa
--- a/SlowPWM.h Tue Jun 18 10:52:51 2019 +0000 +++ b/SlowPWM.h Tue Jun 18 16:22:56 2019 +0000 @@ -1,16 +1,16 @@ -#ifndef __slowPWM.h__ -#define __slowPWM.h__ +#ifndef __SlowPWM_H__ +#define __SlowPWM_H__ #include "mbed.h" -class slowPWM : public DigitalOut +class SlowPWM : public DigitalOut { public: // constructor without setting anything going. - slowPWM( const PinName pin); + SlowPWM( const PinName pin); // constructor that also starts things running - slowPWM( float period, float highTime, const PinName pin ); + SlowPWM( float period, float highTime, const PinName pin ); // set the period void setPeriod(float period);