Eduard Sjoukes
/
PWMout_AnalogIn
How to use a potentiometer to change the duty cycle of a PWM signal
Diff: main.cpp
- Revision:
- 0:1ece86581178
diff -r 000000000000 -r 1ece86581178 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Nov 04 18:23:56 2012 +0000 @@ -0,0 +1,17 @@ +#include "mbed.h" + +PwmOut led(LED1); // Led on board +PwmOut green(p25); // A green led is connected at Pin25 with resistor to ground + +AnalogIn ain(p20); // Potmeter 810k connected between VOUT(3.3V Pin40) and GND (Pin1) with the wiper connect to Pin20 + +int main() { + green.period_us(100); // Set the period to 100uS = 10kHz + led.period_ms(10); // Set the period to 10mS = 100Hz + // Both periods will be set on 10mS, because the same timer is used for both + // Changing the period for one wil change the period for the others also + while(1) { + led = ain; // Set duty cycle for LED1 + green = ain/2; // Set duty cycle for the green led, the "on" time will only the half of the period + } + } \ No newline at end of file