Library to control ESC with PWM signal with period = 20ms
Revision 0:4dcb563001c0, committed 2020-07-28
- Comitter:
- cristian_junca
- Date:
- Tue Jul 28 01:53:14 2020 +0000
- Commit message:
- First code
Changed in this revision
ESC.cpp | Show annotated file Show diff for this revision Revisions of this file |
ESC.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 4dcb563001c0 ESC.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ESC.cpp Tue Jul 28 01:53:14 2020 +0000 @@ -0,0 +1,25 @@ +#include "mbed.h" +#include "ESC.h" + +ESC::ESC(PinName _pin): _pwmPin(_pin){ + _pwmPin.period_us(_period); + init(); +} + +bool ESC::init(){ + _pwmPin.pulsewidth_us(1000); + wait_ms(5000); + return true; +} + +void ESC::speed(float speed){ + _speed = speed; + + if(_speed > 1.0f) + _speed = 1.0f; + else if(_speed < 0.0f) + _speed = 0.0f; + + _speed = (speed * 1000) + 1000; + _pwmPin.pulsewidth_us(_speed); +} \ No newline at end of file
diff -r 000000000000 -r 4dcb563001c0 ESC.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ESC.h Tue Jul 28 01:53:14 2020 +0000 @@ -0,0 +1,14 @@ +#include "mbed.h" + +class ESC{ + + public: + ESC(PinName _pin); + bool init(void); + void speed(float); + + protected: + PwmOut _pwmPin; + static const int32_t _period = 20000; + float _speed; +}; \ No newline at end of file