Wrapper library for ESC PWM throttle control.
Fork of ESC by
Diff: esc.cpp
- Revision:
- 0:ec466ef657a2
- Child:
- 1:4c02fede684b
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/esc.cpp Thu Jun 06 18:57:02 2013 +0000 @@ -0,0 +1,28 @@ +/** + * esc.cpp + * UWB Quadcopter Project + * + * + * @Author + * Mitch Carlson + */ +#include "mbed.h" +#include "esc.h" + +ESC::ESC(PwmOut pwmPinOut, int period) + : esc(pwmPinOut), period(period), throttle(1000) { + esc.period_ms(period); + esc.pulsewidth_us(throttle); + } + +bool ESC::setThrottle(int t) { + if (t >= 0 && t <= 100) { // qualify range + throttle = t*10 + 1000; // map range, 1-2 ms (1000-2000us) + return true; + } + return false; +} + +void ESC::pulse(void) { + esc.pulsewidth_us(throttle); +}