• 강의
  • 커뮤니티
  • 북마크
GCR

자료실

코딩자료 | 타이머와 알람

최고관리자
2019.12.09 09:27 59 0

본문

#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);
      }
  }
  pState = state;
  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;

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);
      }
  }
  pState = state;
  timer.run();
}

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

댓글목록 0

등록된 댓글이 없습니다.