예제 1
#include <SimpleTimer.h>
#define BUTTON 2
#define ALARM 8
#define LED 13
SimpleTimer timer;
int pState = LOW;
boolean booked = false;
void setup() {
pinMode(BUTTON, INPUT);
pinMode(LED, OUTPUT);
}
void loop() {
int state = digitalRead(BUTTON);
if(pState == LOW && state == HIGH) {
if(booked == false) {
booked = true;
digitalWrite(LED, HIGH);
timer.setTimeout(5000, beep); // 5초 뒤에 beep 함수 호출
}
}
pState = state;
timer.run();
}
void beep() {
booked = false;
digitalWrite(LED, LOW);
tone(8, 1000, 20);
delay(100);
tone(8, 1000, 20);
delay(100);
tone(8, 1000, 20);
}
예제 2
#include <SimpleTimer.h>
#define LED 13
SimpleTimer timer;
boolean ledOn = false;
void setup() {
pinMode(LED, OUTPUT);
Serial.begin(9600);
timer.setInterval(1000, toggle); // 1초에 한번씩 toggle 함수 호출
timer.setInterval(5000, notify); // 5초에 한번씩 notify 함수 호출
}
void loop() {
timer.run();
}
void toggle() {
if(ledOn == true) {
digitalWrite(LED, LOW);
} else {
digitalWrite(LED, HIGH);
}
ledOn = !ledOn;
}
void notify() {
Serial.print("Brightenss : ");
Serial.println(analogRead(A0));
}