How to use a potentiometer to change the duty cycle of a PWM signal

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
Eduard
Date:
Sun Nov 04 18:23:56 2012 +0000
Commit message:
Make some explonation text

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Nov 04 18:23:56 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e2ed12d17f06
\ No newline at end of file