05-02 PWMPulse
From Manuals
This example uses an analog input to control the duty cycle of a PWM in a fixed period.
/*Program Example 5.2: Uses analog input to control PWM duty cycle, fixed period
*/
#include "mbed.h"
PwmOut pwm(PWM1);
AnalogIn Ain(A0); //defines analog input on A0
int main() {
while(1){
pwm.period(0.010); // set PWM period to 10 ms
pwm=Ain; //Analog in value becomes PWM duty, both are type float
wait(0.1);
}
}
File:BAM210 05 02 SCH.png
Schematic for example 05-02

