create account

[개발] Arduino 에서 setTimeout 실행 by realmankwon

View this thread on: hive.blogpeakd.comecency.com
· @realmankwon ·
$0.61
[개발] Arduino 에서 setTimeout 실행
안녕하세요 @realmankwon입니다.

아두이노에서 setTimeout 을 쓸 일이 생겼습니다.
다른 언어들은 기본으로 제공을 하지만 아두이노의 경우에는 SimpleTimer 라이브러를 추가 시켜줘야했습니다.
일단 SimpleTimer 를 찾아서 다운로드 받고 라이브러리를 추가시켜주었습니다.

- https://playground.arduino.cc/Code/SimpleTimer/
- 소스 경로 : https://github.com/schinken/SimpleTimer

소스 파일을 zip으로 받은 후에 .zip 라이브러리 추가를 해주면 외부 라이브러리가 추가가 됩니다.

![](https://cdn.steemitimages.com/DQmdYbF4s1NSnbiyavXSd9dYK8XxqWkKqWBprK8E6DcDHs5/image.png)

### 1 . 라이브러리 선언
~~~
#include <SimpleTimer.h> 
~~~

### 2 . timer 변수 선언
~~~
SimpleTimer timer;
int timerId;
~~~

### 3 . setTimeout 호출
- setTimeout 호출시 return 값을 저장해 둡니다.
- return 값은 해당 timer  스레드의 ID 이며 필요시 스레드를 중단시키거나 재실행하는데 사용됩니다.
~~~
  timerId = timer.setTimeout(3000, [function]);
~~~

### 4 . timer 중단 및 재실행
~~~
  if(timer.isEnabled(timerId)) timer.disable(timerId);
~~~

### 5 . timer 실행
- 가장 중요한 것은 loop() 함수에서 timer를 실행시켜주어야 하는 것입니다.
- 아래의 실행 부분이 없으면 setTimeout은 실행되지 않습니다.
~~~
void loop(){
    .....
    .....

    timer.run();
}
~~~

언어를 넘나들다보니 더 많은 것을 알아간다기 보다 더 많은 혼란이 가중되는 느낌이네요. ㅎㅎ
이렇게 정리를 해놔야 나중에 도움이 될 것 같아서 요즘은 항상 정리를 하고 있습니다.
👍  , , , , , , , , , , , , , , , , , , , , , ,
properties (23)
authorrealmankwon
permlinkrealmankwon-posting-2020-10-06-16-36
categoryhive-132971
json_metadata{"tags":["sct","sct-kr","sct-freeboard","s","union","zzan","dev","mini","kr","sago"],"app":"steemcoinpan/0.1"}
created2020-10-06 07:38:39
last_update2020-10-06 07:38:39
depth0
children0
last_payout2020-10-13 07:38:39
cashout_time1969-12-31 23:59:59
total_payout_value0.348 HBD
curator_payout_value0.265 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,115
author_reputation256,638,399,773,710
root_title"[개발] Arduino 에서 setTimeout 실행"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id99,986,953
net_rshares3,609,522,500,001
author_curate_reward""
vote details (23)