David Estrada
/
HW4_1_Q3
Leds get brighter as it gets darker outside
Revision 0:00bceb1fa958, committed 2015-09-16
- Comitter:
- destradafilm
- Date:
- Wed Sep 16 16:24:20 2015 +0000
- Commit message:
- HW 4.1 q3
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 00bceb1fa958 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Sep 16 16:24:20 2015 +0000 @@ -0,0 +1,33 @@ +#include "mbed.h" + +#define PROGNAME "DEstra_HW 4_1 QUESTION 3" +#define DATATIME 0.5 + +#define PRINTDEBUG + +AnalogIn LightSensor(PTE22); // define light sensor +PwmOut redLed(LED_RED); +PwmOut greenLed(LED_GREEN); + +Serial pc(USBTX, USBRX); + +int main() +{ + float lightVal; + unsigned short lightWord; + + pc.printf(PROGNAME); + + while(true){ + lightVal = LightSensor.read(); + lightWord = LightSensor.read_u16(); + redLed = 1.0 - lightVal; // redLed shines brighter as it gets darker outside + greenLed = 1.0 - lightVal; + + #ifdef PRINTDEBUG + pc.printf("LS => %1.3f %5 \r\n", (1.0 - lightVal), lightWord); + pc.printf("other => %\r\n", lightWord); + #endif + wait(DATATIME); + } +} \ No newline at end of file
diff -r 000000000000 -r 00bceb1fa958 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Sep 16 16:24:20 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/ba1f97679dad \ No newline at end of file