카테고리 없음

(아두이노) 간편한 타이머 라이브러리 MsTimer2

미친토끼 2025. 6. 10. 22:52

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
const int led_pin = 13;			// default to pin 13

void flash()
{
  static boolean output = HIGH;
  
  digitalWrite(led_pin, output);
  output = !output;
}

void setup()
{
  pinMode(led_pin, OUTPUT);

  MsTimer2::set(500, flash); // 500ms period
  MsTimer2::start();
}

void loop()
{
}