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
Diff: main.cpp
- Revision:
- 2:e94dce9a7464
- Parent:
- 1:3b84da6d133f
- Child:
- 3:9be917b0d07a
diff -r 3b84da6d133f -r e94dce9a7464 main.cpp
--- a/main.cpp Fri Oct 13 03:25:04 2017 +0000
+++ b/main.cpp Sun Oct 15 11:33:09 2017 +0000
@@ -1,42 +1,36 @@
-// Blink until timeout.
+/* Ticker : 함수를 쓰는 시간에 시작하여 원하는 시간이 지나면 특정 함수를 호출하고
+다시 초기화 하여 원하는 시간이 되면 호출하는 것을 반복한다.*/
+
+/*결과: red_LED 5초동안 깜빡이다가 5초동안 멈추는것을 반복*/
+
#include "mbed.h"
-Timeout timeout;
-DigitalOut led(D13);
+Ticker timer;
+//DigitalOut ledg(LED2);
+DigitalOut ledr(LED1);
-int secFlag = 1;
-int secTic=0;
+int flip=0;
-void attimeout() {
- secFlag=1;
-
-
+void attime() {
+ flip =!flip;
}
int main() {
-
+ timer.attach(&attime,5); //메인 함수는 계속 실행이 되면서 5초 뒤에 attime을 호출한다. 반복적으로
while(1) {
- if(secFlag) //1s
+ if(flip==0)
{
- secFlag=0;
- timeout.attach(&attimeout, 1);
+ ledr =! ledr;
+ }
- secTic++;
- }
-
- if(secTic==1)
- { led =0;
- wait(0.5);
- led =1;
- wait(0.5);
- }
+ else {
+ ledr=1;
+ // ledg = !ledg;
+ }
+
+ wait(0.2);
- if(secTic==10)
- { led =0;
- wait(0.5);
- led =1;
- wait(0.5);
- }
- }
+ }
+
}
