Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Seeed_Motor_Shield_HelloWorld Official_MedusaIcon Seeed_Motor_Shield adrobo
SoftwarePWM Class Reference
Class to control a servo on any pin, without using pwm. More...
#include <SoftwarePWM.h>
Public Member Functions | |
| SoftwarePWM (PinName Pin) | |
| Create a new SoftwarePWM object on any mbed pin. | |
| void | SetPosition (int NewPos) |
| Change the position of the PWM. | |
| void | Enable (int StartPos, int Period) |
| Enable the PWM. | |
| void | Disable () |
| Disable the PWM. | |
Detailed Description
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.
Constructor & Destructor Documentation
| SoftwarePWM | ( | PinName | Pin ) |
Create a new SoftwarePWM object on any mbed pin.
- Parameters:
-
Pin Pin on mbed to connect PWM device to
Definition at line 4 of file SoftwarePWM.cpp.
Member Function Documentation
| void Disable | ( | ) |
Disable the PWM.
After disabling the PWM won't get any signal anymore
Definition at line 28 of file SoftwarePWM.cpp.
| void Enable | ( | int | StartPos, |
| int | Period | ||
| ) |
Enable the PWM.
Without enabling the PWM won't be running. Startposition and period both in us.
- Parameters:
-
StartPos The position of the PWM to start (us) Period The time between every pulse. 20000 us = 50 Hz(standard) (us)
Definition at line 23 of file SoftwarePWM.cpp.
| void SetPosition | ( | int | NewPos ) |
Change the position of the PWM.
Position in us
- Parameters:
-
NewPos The new value of the PWM position (us)
Definition at line 6 of file SoftwarePWM.cpp.
Generated on Tue Jul 12 2022 21:20:52 by
1.7.2