본문 바로가기
임베디드/Arduino

타이머 인터럽트 Timer interrupt

by sj0020 2020. 9. 3.
#include <MsTimer2.h>

const int RED = 13;
const int BLUE = 12;
volatile int output = HIGH;

void flash()
{
  digitalWrite(BLUE, output);
  output = !output;
}

void setup()
{
  pinMode(RED, OUTPUT);
  pinMode(BLUE, OUTPUT);
  MsTimer2::set(500, flash); // 500ms period
  MsTimer2::start();
}

void loop()
{
  digitalWrite(RED, HIGH);
  delay(2000);
  digitalWrite(RED, LOW);
  delay(2000);
}