Kojo / SoftwarePWM

Dependents:   Seeed_Motor_Shield_HelloWorld Official_MedusaIcon Seeed_Motor_Shield adrobo

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SoftwarePWM.cpp Source File

SoftwarePWM.cpp

00001 #include "SoftwarePWM.h"
00002 #include "mbed.h"
00003 
00004 SoftwarePWM::SoftwarePWM(PinName Pin) : SoftwarePWMPin(Pin) {}
00005 
00006 void SoftwarePWM::SetPosition(int Pos) {
00007     Position = Pos;
00008 }
00009 
00010 void SoftwarePWM::StartPulse() {
00011     if(Position <= 0) {
00012         SoftwarePWMPin = 0 ;
00013     } else {
00014         SoftwarePWMPin = 1;
00015         PulseStop.attach_us(this, &SoftwarePWM::EndPulse, Position);
00016     }
00017 }
00018 
00019 void SoftwarePWM::EndPulse() {
00020     SoftwarePWMPin = 0;
00021 }
00022 
00023 void SoftwarePWM::Enable(int StartPos, int Period) {
00024     Position = StartPos;
00025     Pulse.attach_us(this, &SoftwarePWM::StartPulse, Period);
00026 }
00027 
00028 void SoftwarePWM::Disable() {
00029     Pulse.detach();
00030 }