Rob Toulson / Mbed 2 deprecated PE_04-05_PWMDCMotor

Dependencies:   mbed

Committer:
robt
Date:
Fri Aug 31 16:07:35 2012 +0000
Revision:
0:76b527fa897e
by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"

Who changed what in which revision?

UserRevisionLine numberNew contents of line
robt 0:76b527fa897e 1 /*Program Example 4.5: PWM control to DC motor is repeatedly ramped
robt 0:76b527fa897e 2 */
robt 0:76b527fa897e 3 #include "mbed.h"
robt 0:76b527fa897e 4 PwmOut PWM1(p21);
robt 0:76b527fa897e 5 float i;
robt 0:76b527fa897e 6 int main()
robt 0:76b527fa897e 7 {
robt 0:76b527fa897e 8 PWM1.period(0.010); //set PWM period to 10 ms
robt 0:76b527fa897e 9 while(1) {
robt 0:76b527fa897e 10 for (i=0; i<1; i=i+0.01) {
robt 0:76b527fa897e 11 PWM1=i; // update PWM duty cycle
robt 0:76b527fa897e 12 wait(0.2);
robt 0:76b527fa897e 13 }
robt 0:76b527fa897e 14 }
robt 0:76b527fa897e 15 }