Junichi Katsu
/
Grove_LightSensor
GROVE - 光センサ サンプルプログラム
main.cpp@1:1b7b641caea5, 2013-11-30 (annotated)
- Committer:
- jksoft
- Date:
- Sat Nov 30 02:01:04 2013 +0000
- Revision:
- 1:1b7b641caea5
- Parent:
- 0:9a4f94089a39
?????????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jksoft | 0:9a4f94089a39 | 1 | #include "mbed.h" |
jksoft | 0:9a4f94089a39 | 2 | |
jksoft | 1:1b7b641caea5 | 3 | #define GAIN 1.4 |
jksoft | 1:1b7b641caea5 | 4 | |
jksoft | 0:9a4f94089a39 | 5 | BusOut myleds(LED1, LED2, LED3, LED4); |
jksoft | 0:9a4f94089a39 | 6 | AnalogIn LightSensor(p15); |
jksoft | 0:9a4f94089a39 | 7 | |
jksoft | 0:9a4f94089a39 | 8 | int main() { |
jksoft | 0:9a4f94089a39 | 9 | while(1) { |
jksoft | 0:9a4f94089a39 | 10 | float value = LightSensor; |
jksoft | 0:9a4f94089a39 | 11 | int ledbit = 0x00; |
jksoft | 0:9a4f94089a39 | 12 | |
jksoft | 1:1b7b641caea5 | 13 | value *= GAIN; |
jksoft | 1:1b7b641caea5 | 14 | |
jksoft | 0:9a4f94089a39 | 15 | if( value > 0.8 ) { |
jksoft | 0:9a4f94089a39 | 16 | ledbit = 0x0F; |
jksoft | 0:9a4f94089a39 | 17 | } |
jksoft | 0:9a4f94089a39 | 18 | else if( value > 0.6 ) { |
jksoft | 0:9a4f94089a39 | 19 | ledbit = 0x07; |
jksoft | 0:9a4f94089a39 | 20 | } |
jksoft | 0:9a4f94089a39 | 21 | else if( value > 0.4 ) { |
jksoft | 0:9a4f94089a39 | 22 | ledbit = 0x03; |
jksoft | 0:9a4f94089a39 | 23 | } |
jksoft | 0:9a4f94089a39 | 24 | else if( value > 0.2 ) { |
jksoft | 0:9a4f94089a39 | 25 | ledbit = 0x01; |
jksoft | 0:9a4f94089a39 | 26 | } |
jksoft | 0:9a4f94089a39 | 27 | else { |
jksoft | 0:9a4f94089a39 | 28 | ledbit = 0x00; |
jksoft | 0:9a4f94089a39 | 29 | } |
jksoft | 1:1b7b641caea5 | 30 | |
jksoft | 1:1b7b641caea5 | 31 | myleds = ledbit; |
jksoft | 0:9a4f94089a39 | 32 | printf("Value = %f\r\n",value); |
jksoft | 0:9a4f94089a39 | 33 | wait(0.2); |
jksoft | 0:9a4f94089a39 | 34 | } |
jksoft | 0:9a4f94089a39 | 35 | } |