Kojo / SoftwarePWM

Dependents:   Seeed_Motor_Shield_HelloWorld Official_MedusaIcon Seeed_Motor_Shield adrobo

Embed: (wiki syntax)

« Back to documentation index

SoftwarePWM Class Reference

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:
PinPin 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:
StartPosThe position of the PWM to start (us)
PeriodThe 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:
NewPosThe new value of the PWM position (us)

Definition at line 6 of file SoftwarePWM.cpp.