sho hashimoto
/
cds_led_serial
control LED by CdS http://shokai.org/blog/archives/5103
Revision 1:83f0bc743127, committed 2010-04-22
- Comitter:
- shokai
- Date:
- Thu Apr 22 08:17:48 2010 +0000
- Parent:
- 0:60e8027b95d9
- Commit message:
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 60e8027b95d9 -r 83f0bc743127 main.cpp --- a/main.cpp Wed Apr 21 08:32:52 2010 +0000 +++ b/main.cpp Thu Apr 22 08:17:48 2010 +0000 @@ -1,29 +1,19 @@ #include "mbed.h" -Serial pc(USBTX, USBRX); // tx, rx +Serial pc(USBTX, USBRX); -DigitalOut led1(LED1); +DigitalOut led1(LED1); // on board LED DigitalOut led2(p11); AnalogIn adc(p15); -int ain; +float ain; int main() { while(1) { - if(led1){ - led1 = 0; - } - else{ - led1 = 1; - } + led1 = !led1; // blink LED ain = adc; - if(adc < 0.4){ - led2 = 1; - } - else{ - led2 = 0; - } - pc.printf("%f", (double)adc); - pc.printf("\r\n"); + if(ain < 0.4) led2 = 1; + else led2 = 0; + pc.printf("%f\r\n", (float)ain); wait(0.3); } }