![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
ハイパー・マイコン mbedでインターネット 電子工作 1章 リスト1-1 HumanDetection のプログラム
main.cpp@0:a5beca894c46, 2014-07-09 (annotated)
- Committer:
- sunifu
- Date:
- Wed Jul 09 13:06:03 2014 +0000
- Revision:
- 0:a5beca894c46
????????? mbed???????? ???? ??? 1-1 ( HumanDetection)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sunifu | 0:a5beca894c46 | 1 | #include "mbed.h" |
sunifu | 0:a5beca894c46 | 2 | |
sunifu | 0:a5beca894c46 | 3 | #define INIT 7.0 |
sunifu | 0:a5beca894c46 | 4 | #define NOISE 3.0 |
sunifu | 0:a5beca894c46 | 5 | #define DELAY 10.0 |
sunifu | 0:a5beca894c46 | 6 | |
sunifu | 0:a5beca894c46 | 7 | Ticker flipper; |
sunifu | 0:a5beca894c46 | 8 | |
sunifu | 0:a5beca894c46 | 9 | DigitalOut led1(LED1); |
sunifu | 0:a5beca894c46 | 10 | DigitalOut led2(LED2); |
sunifu | 0:a5beca894c46 | 11 | DigitalOut led3(LED3); |
sunifu | 0:a5beca894c46 | 12 | DigitalIn msensor(p20); |
sunifu | 0:a5beca894c46 | 13 | |
sunifu | 0:a5beca894c46 | 14 | void flip() { |
sunifu | 0:a5beca894c46 | 15 | led1 = !led1; |
sunifu | 0:a5beca894c46 | 16 | } |
sunifu | 0:a5beca894c46 | 17 | |
sunifu | 0:a5beca894c46 | 18 | int main() { |
sunifu | 0:a5beca894c46 | 19 | led2 = 0; |
sunifu | 0:a5beca894c46 | 20 | led3 = 0; |
sunifu | 0:a5beca894c46 | 21 | |
sunifu | 0:a5beca894c46 | 22 | flipper.attach(&flip, 0.3); |
sunifu | 0:a5beca894c46 | 23 | wait( INIT ); |
sunifu | 0:a5beca894c46 | 24 | flipper.detach(); |
sunifu | 0:a5beca894c46 | 25 | led1=0; |
sunifu | 0:a5beca894c46 | 26 | |
sunifu | 0:a5beca894c46 | 27 | while(1) { |
sunifu | 0:a5beca894c46 | 28 | led2 = msensor; |
sunifu | 0:a5beca894c46 | 29 | if ( led2 == 1 ){ |
sunifu | 0:a5beca894c46 | 30 | wait( NOISE ); |
sunifu | 0:a5beca894c46 | 31 | led2 = msensor; |
sunifu | 0:a5beca894c46 | 32 | |
sunifu | 0:a5beca894c46 | 33 | while ( led2 == 1 ){ |
sunifu | 0:a5beca894c46 | 34 | led3 = 1; |
sunifu | 0:a5beca894c46 | 35 | wait( DELAY ) ; |
sunifu | 0:a5beca894c46 | 36 | led2 = msensor; |
sunifu | 0:a5beca894c46 | 37 | } |
sunifu | 0:a5beca894c46 | 38 | led3 = 0; |
sunifu | 0:a5beca894c46 | 39 | } |
sunifu | 0:a5beca894c46 | 40 | } |
sunifu | 0:a5beca894c46 | 41 | } |