Simplified pwm pinout to ESC control library for the KL25Z

Dependencies:   esb_gcc

Dependents:   esp

Fork of ESC by Mitch Carlson

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers esc.cpp Source File

esc.cpp

00001 #include "mbed.h"
00002 #include "esc.h"
00003 
00004 ESC::ESC(PwmOut pwmPinOut, int period)
00005     : esc(pwmPinOut), period(period), throttle(1000) {
00006         esc.period_ms(period);
00007         esc.pulsewidth_us(throttle);
00008     }
00009 
00010 bool ESC::setThrottle(int t) {
00011     if (t >= 0 && t <= 100) {       // qualify range, 0-100
00012         throttle = t*10 + 1000;     // map to range, 1-2 ms (1000-2000us)
00013         esc.pulsewidth_us(throttle);
00014         return true;
00015     }
00016     return false;
00017 }
00018 
00019 void ESC::pulse(void) {
00020     esc.pulsewidth_us(throttle);
00021 }