Arduino/인터럽트
MsTimer2를 이용한 LED 켜고 끄기
DesignatedRoom
2020. 10. 23. 18:30
타이머를 이용한 인터럽트이다.
mstimer2 라이브러리를 설치하자.
소스 코드
더보기
/*
MsTimer2 is a small and very easy to use library to interface Timer2 with
humans. It's called MsTimer2 because it "hardcodes" a resolution of 1
millisecond on timer2
For Details see: http://www.arduino.cc/playground/Main/MsTimer2
*/
#include <MsTimer2.h>
// Switch on LED on and off each half second
// flash함수가 호출이 될 때마다 LED가 켜지거나 꺼지는 것이 반복된다.
void flash()
{
static boolean output = HIGH;
digitalWrite(13, output);
output = !output;
}
void setup()
{
pinMode(13, OUTPUT);
// 0.5초마다 flash함수를 호출하도록 설정
MsTimer2::set(300, flash); // 500ms period
MsTimer2::start();
}
void loop()
{
}