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.cpp@0:1e86036581bd, 2012-04-05 (annotated)
- Committer:
- takashikojo
- Date:
- Thu Apr 05 07:09:39 2012 +0000
- Revision:
- 0:1e86036581bd
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| takashikojo | 0:1e86036581bd | 1 | #include "SoftwarePWM.h" |
| takashikojo | 0:1e86036581bd | 2 | #include "mbed.h" |
| takashikojo | 0:1e86036581bd | 3 | |
| takashikojo | 0:1e86036581bd | 4 | SoftwarePWM::SoftwarePWM(PinName Pin) : SoftwarePWMPin(Pin) {} |
| takashikojo | 0:1e86036581bd | 5 | |
| takashikojo | 0:1e86036581bd | 6 | void SoftwarePWM::SetPosition(int Pos) { |
| takashikojo | 0:1e86036581bd | 7 | Position = Pos; |
| takashikojo | 0:1e86036581bd | 8 | } |
| takashikojo | 0:1e86036581bd | 9 | |
| takashikojo | 0:1e86036581bd | 10 | void SoftwarePWM::StartPulse() { |
| takashikojo | 0:1e86036581bd | 11 | if(Position <= 0) { |
| takashikojo | 0:1e86036581bd | 12 | SoftwarePWMPin = 0 ; |
| takashikojo | 0:1e86036581bd | 13 | } else { |
| takashikojo | 0:1e86036581bd | 14 | SoftwarePWMPin = 1; |
| takashikojo | 0:1e86036581bd | 15 | PulseStop.attach_us(this, &SoftwarePWM::EndPulse, Position); |
| takashikojo | 0:1e86036581bd | 16 | } |
| takashikojo | 0:1e86036581bd | 17 | } |
| takashikojo | 0:1e86036581bd | 18 | |
| takashikojo | 0:1e86036581bd | 19 | void SoftwarePWM::EndPulse() { |
| takashikojo | 0:1e86036581bd | 20 | SoftwarePWMPin = 0; |
| takashikojo | 0:1e86036581bd | 21 | } |
| takashikojo | 0:1e86036581bd | 22 | |
| takashikojo | 0:1e86036581bd | 23 | void SoftwarePWM::Enable(int StartPos, int Period) { |
| takashikojo | 0:1e86036581bd | 24 | Position = StartPos; |
| takashikojo | 0:1e86036581bd | 25 | Pulse.attach_us(this, &SoftwarePWM::StartPulse, Period); |
| takashikojo | 0:1e86036581bd | 26 | } |
| takashikojo | 0:1e86036581bd | 27 | |
| takashikojo | 0:1e86036581bd | 28 | void SoftwarePWM::Disable() { |
| takashikojo | 0:1e86036581bd | 29 | Pulse.detach(); |
| takashikojo | 0:1e86036581bd | 30 | } |