Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of Ticker_3 by
main.cpp@3:9be917b0d07a, 2017-10-15 (annotated)
- Committer:
- ajy912
- Date:
- Sun Oct 15 11:48:11 2017 +0000
- Revision:
- 3:9be917b0d07a
- Parent:
- 2:e94dce9a7464
- Child:
- 4:af3ab097055c
Ticker_2
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ajy912 | 2:e94dce9a7464 | 1 | /* Ticker : 함수를 쓰는 시간에 시작하여 원하는 시간이 지나면 특정 함수를 호출하고 |
| ajy912 | 2:e94dce9a7464 | 2 | 다시 초기화 하여 원하는 시간이 되면 호출하는 것을 반복한다.*/ |
| ajy912 | 2:e94dce9a7464 | 3 | |
| ajy912 | 3:9be917b0d07a | 4 | /*결과: red_LED 5초동안 깜빡이다가 green_LED 5초동안 깜빡이는 것을 반복*/ |
| ajy912 | 2:e94dce9a7464 | 5 | |
| ajy912 | 0:0ba4641adab9 | 6 | |
| ajy912 | 0:0ba4641adab9 | 7 | #include "mbed.h" |
| ajy912 | 0:0ba4641adab9 | 8 | |
| ajy912 | 2:e94dce9a7464 | 9 | Ticker timer; |
| ajy912 | 3:9be917b0d07a | 10 | DigitalOut ledg(D3); |
| ajy912 | 3:9be917b0d07a | 11 | DigitalOut ledr(D2); |
| ajy912 | 0:0ba4641adab9 | 12 | |
| ajy912 | 2:e94dce9a7464 | 13 | int flip=0; |
| ajy912 | 1:3b84da6d133f | 14 | |
| ajy912 | 2:e94dce9a7464 | 15 | void attime() { |
| ajy912 | 2:e94dce9a7464 | 16 | flip =!flip; |
| ajy912 | 0:0ba4641adab9 | 17 | } |
| ajy912 | 0:0ba4641adab9 | 18 | |
| ajy912 | 0:0ba4641adab9 | 19 | int main() { |
| ajy912 | 2:e94dce9a7464 | 20 | timer.attach(&attime,5); //메인 함수는 계속 실행이 되면서 5초 뒤에 attime을 호출한다. 반복적으로 |
| ajy912 | 0:0ba4641adab9 | 21 | while(1) { |
| ajy912 | 2:e94dce9a7464 | 22 | if(flip==0) |
| ajy912 | 1:3b84da6d133f | 23 | { |
| ajy912 | 2:e94dce9a7464 | 24 | ledr =! ledr; |
| ajy912 | 3:9be917b0d07a | 25 | |
| ajy912 | 2:e94dce9a7464 | 26 | } |
| ajy912 | 1:3b84da6d133f | 27 | |
| ajy912 | 2:e94dce9a7464 | 28 | else { |
| ajy912 | 3:9be917b0d07a | 29 | |
| ajy912 | 3:9be917b0d07a | 30 | ledg = !ledg; |
| ajy912 | 2:e94dce9a7464 | 31 | } |
| ajy912 | 2:e94dce9a7464 | 32 | |
| ajy912 | 2:e94dce9a7464 | 33 | wait(0.2); |
| ajy912 | 1:3b84da6d133f | 34 | |
| ajy912 | 2:e94dce9a7464 | 35 | } |
| ajy912 | 2:e94dce9a7464 | 36 | |
| ajy912 | 0:0ba4641adab9 | 37 | } |
