#include <SoftwarePWM.h>
Public Member Functions | |
void | Disable () |
void | Enable (int StartPos, int Period) |
void | SetPosition (int NewPos) |
SoftwarePWM (PinName Pin) | |
Private Member Functions | |
void | EndPulse () |
void | StartPulse () |
Private Attributes | |
int | Position |
Ticker | Pulse |
Timeout | PulseStop |
DigitalOut | SoftwarePWMPin |
Class to control a servo on any pin, without using pwm
Example:
// Keep sweeping servo from left to right #include "mbed.h" #include "Servo.h" Servo Servo1(p20); Servo1.Enable(1500,20000); while(1) { for (int pos = 1000; pos < 2000; pos += 25) { Servo1.SetPosition(pos); wait_ms(20); } for (int pos = 2000; pos > 1000; pos -= 25) { Servo1.SetPosition(pos); wait_ms(20); } }
Definition at line 55 of file SoftwarePWM.h.
SoftwarePWM::SoftwarePWM | ( | PinName | Pin | ) |
Create a new SoftwarePWM object on any mbed pin
Pin | Pin on mbed to connect PWM device to |
Definition at line 4 of file SoftwarePWM.cpp.
void SoftwarePWM::Disable | ( | ) |
Disable the PWM. After disabling the PWM won't get any signal anymore
Definition at line 35 of file SoftwarePWM.cpp.
void SoftwarePWM::Enable | ( | int | StartPos, |
int | Period | ||
) |
Enable the PWM. Without enabling the PWM won't be running. Startposition and period both in us.
StartPos | The position of the PWM to start (us) |
Period | The time between every pulse. 20000 us = 50 Hz(standard) (us) |
Definition at line 29 of file SoftwarePWM.cpp.
void SoftwarePWM::EndPulse | ( | ) | [private] |
Definition at line 24 of file SoftwarePWM.cpp.
void SoftwarePWM::SetPosition | ( | int | NewPos | ) |
Change the position of the PWM. Position in us
NewPos | The new value of the PWM position (us) |
Definition at line 6 of file SoftwarePWM.cpp.
void SoftwarePWM::StartPulse | ( | ) | [private] |
Definition at line 11 of file SoftwarePWM.cpp.
int SoftwarePWM::Position [private] |
Definition at line 87 of file SoftwarePWM.h.
Ticker SoftwarePWM::Pulse [private] |
Definition at line 89 of file SoftwarePWM.h.
Timeout SoftwarePWM::PulseStop [private] |
Definition at line 90 of file SoftwarePWM.h.
DigitalOut SoftwarePWM::SoftwarePWMPin [private] |
Definition at line 88 of file SoftwarePWM.h.