본문으로 건너뛰기

제품소개 준비중입니다.

빠른시일 내 오픈하도록 노력하겠습니다.
감사합니다.


자료실

만지고 만들면서 쉽게 배우는, 글로벌 코딩


자료실

코딩자료 | 타이머와 알람


페이지 정보

작성자 글로벌코딩 작성일17-04-24 07:33 조회수 471회

본문

#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);
} // if (booked == false)
} // if (pState)
pState = state;
timer.run();
} // loop
void beep(){ booked = false;
digitalWrite(LED, LOW);
tone(8, 1000, 20);
delay(100);
tone(8, 1000, 20);
delay(100);
tone(8, 1000, 20);
}

 

 

 

=======================================================================

 

 

#include <SimpleTimer.h>
#define BUTTON 2
#define ALARM 8
#define LED 13
SimpleTimer timer;


void setup(){
pinMode(BUTTON, INPUT);
pinMode(LED, OUTPUT);
}
void loop(){
int state = digitalRead(BUTTON);

if(state == HIGH){
digitalWrite(LED, HIGH);
timer.setTimeout(5000, beep);
}

timer.run();
}
void beep(){
digitalWrite(LED, LOW);
tone(8, 1000, 20);
delay(100);
tone(8, 1000, 20);
delay(100);
tone(8, 1000, 20);

 

====================================================================

 

#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(state == HIGH){
if(booked == false){
booked = true;
digitalWrite(LED, HIGH);
timer.setTimeout(1000, beep);
} // if (booked == false)
} // if (pState)
pState = state;
timer.run();
} // loop
void beep(){ booked = false;
digitalWrite(LED, LOW);
tone(8, 1000, 20);
delay(1000);
tone(8, 1000, 20);
delay(100);
tone(8, 1000, 20);
}


첨부파일