
Test the PWM functionality in conjunction with an analog input - drive the brightness of a LCD backlight with the ambient light level. Serves as testcase of a PWM problem, see code comment.
Revision 0:708a1d284406, committed 2011-01-19
- Comitter:
- hlipka
- Date:
- Wed Jan 19 19:46:05 2011 +0000
- Commit message:
- initial test version
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 |
diff -r 000000000000 -r 708a1d284406 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Jan 19 19:46:05 2011 +0000 @@ -0,0 +1,38 @@ +#include "mbed.h" + +#include "math.h" + +/* + read the light value from a photo transistor connected to P20 and + drive a LCDs LED backlight connected to P25. + The backlight should dimm in the dark and brighten up when the lights go on. + + NOTE: the version below doesn't work, remove the printf in line 35! +*/ +int main() { + DigitalOut led1(LED1); + float f=0.0; + PwmOut display(p25); + display.period_ms(1); + display=f; + + AnalogIn light(p20); + + for (int i=0;i<100;i++) + { + f=f+0.01; + display=f; + wait (0.03); + } + printf("%f\n",display.read()); + led1=1; + + while (true) + { + double d=light; + double sq=pow(d,0.6); + display.write(sq*3); + printf("%f / %f\n",d,sq); + wait(1); + } +}
diff -r 000000000000 -r 708a1d284406 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Jan 19 19:46:05 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e