Friday, August 21, 2015

Infrared with interrupt

const int irRelayPin = 4; // the number of the pushbutton pin
const int alarmPin = 13; // the number of the Buzzer pin
// variables will change:
int irState = 0; // variable for reading the pushbutton status
void setup() {
attachInterrupt(0, stopAlarm, FALLING);
// initialize the LED pin as an output:
pinMode(alarmPin, OUTPUT); 
// initialize the pushbutton pin as an input:
pinMode(irRelayPin, INPUT); 
}
void loop(){
// read the state of the pushbutton value:
irState = digitalRead(irRelayPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (irState == HIGH) { 
// turn LED on: 
digitalWrite(alarmPin, HIGH); 
//Serial.println("alarm");
delay(10 * 60 * 1000); //bunyikan alarm selama 10 menit
digitalWrite(alarmPin, LOW); //matiin

}
void stopAlarm(){
digitalWrite(alarmPin, LOW); //stop alarm
}

No comments:

Post a Comment