Akira Kashihara
/
Challenge2_easy
work shop sample
main.cpp@0:946287229e5e, 2012-10-24 (annotated)
- Committer:
- AkiraK
- Date:
- Wed Oct 24 08:29:30 2012 +0000
- Revision:
- 0:946287229e5e
Challenge2_easy;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AkiraK | 0:946287229e5e | 1 | #include "mbed.h" |
AkiraK | 0:946287229e5e | 2 | |
AkiraK | 0:946287229e5e | 3 | DigitalOut myleds[] = {LED1, LED2, LED3, LED4}; |
AkiraK | 0:946287229e5e | 4 | AnalogIn illu(p15); |
AkiraK | 0:946287229e5e | 5 | |
AkiraK | 0:946287229e5e | 6 | int main() |
AkiraK | 0:946287229e5e | 7 | { |
AkiraK | 0:946287229e5e | 8 | while(true) { |
AkiraK | 0:946287229e5e | 9 | float lx = illu * 3.3 / 3 * 1000; |
AkiraK | 0:946287229e5e | 10 | printf("%4.2f\n", lx); |
AkiraK | 0:946287229e5e | 11 | |
AkiraK | 0:946287229e5e | 12 | if( 250 > lx && lx > 0) { |
AkiraK | 0:946287229e5e | 13 | myleds[0] = 1; |
AkiraK | 0:946287229e5e | 14 | for(int i = 1; i <4; i++) { |
AkiraK | 0:946287229e5e | 15 | myleds[i] = 0; |
AkiraK | 0:946287229e5e | 16 | } |
AkiraK | 0:946287229e5e | 17 | }else |
AkiraK | 0:946287229e5e | 18 | |
AkiraK | 0:946287229e5e | 19 | if(500 > lx && lx >= 250) { |
AkiraK | 0:946287229e5e | 20 | myleds[0] = 1; |
AkiraK | 0:946287229e5e | 21 | myleds[1] = 1; |
AkiraK | 0:946287229e5e | 22 | myleds[2] = 0; |
AkiraK | 0:946287229e5e | 23 | myleds[3] = 0; |
AkiraK | 0:946287229e5e | 24 | }else |
AkiraK | 0:946287229e5e | 25 | |
AkiraK | 0:946287229e5e | 26 | if(750 > lx && lx >= 500) { |
AkiraK | 0:946287229e5e | 27 | for(int x = 0; x < 3; x++) { |
AkiraK | 0:946287229e5e | 28 | myleds[x] = 1; |
AkiraK | 0:946287229e5e | 29 | } |
AkiraK | 0:946287229e5e | 30 | myleds[3] = 0; |
AkiraK | 0:946287229e5e | 31 | }else |
AkiraK | 0:946287229e5e | 32 | |
AkiraK | 0:946287229e5e | 33 | if(lx >= 750) { |
AkiraK | 0:946287229e5e | 34 | for(int y = 0; y < 4; y++) { |
AkiraK | 0:946287229e5e | 35 | myleds[y] = 1; |
AkiraK | 0:946287229e5e | 36 | } |
AkiraK | 0:946287229e5e | 37 | } |
AkiraK | 0:946287229e5e | 38 | } |
AkiraK | 0:946287229e5e | 39 | } |