A test program for the PWMAverage library. This program will print the average duty cycle of a signal (1Hz-100kHz) after a button is pressed for a few seconds.

Dependencies:   PWMAverage mbed

Revision:
0:a84599c324fb
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Aug 29 11:51:28 2012 +0000
@@ -0,0 +1,33 @@
+// Measure and print the average duty cycle of a signal connected to p29 and p30 (together) while the button (p16) is pulled high
+
+#include "mbed.h"
+#include "PWMAverage.h"
+
+DigitalOut myled(LED1);
+
+PWMAverage pa(p29,p30);
+
+DigitalIn button (p16);
+
+Timer tmr;
+
+int main()
+{
+    button.mode(PullDown);
+    while(1)
+    {
+        pa.reset();
+    
+        while (!button) {}
+        pa.start();
+        tmr.start();
+        myled=1;
+    
+        while (button) {}
+        pa.stop();
+        tmr.stop();
+        myled=0;
+    
+        printf("Average dudy cycle over %d us was %.4f\n\r",tmr.read_us(),pa.read());
+    }
+}
\ No newline at end of file