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.
main.cpp
- Committer:
- p07gbar
- Date:
- 2012-08-29
- Revision:
- 0:a84599c324fb
File content as of revision 0:a84599c324fb:
// 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()); } }