Created
April 18, 2020 16:42
-
-
Save handeyeco/00487e78325fe00eee24ce60451e9ad1 to your computer and use it in GitHub Desktop.
Arduino Audio Alarm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int relay = 2; | |
int input = 3; | |
int startBeep = 0; | |
int beepLength = 1000; | |
void setup() { | |
pinMode(relay, OUTPUT); | |
pinMode(input, INPUT); | |
Serial.begin(9600); | |
} | |
void loop() { | |
if (startBeep == 0) { | |
int reading = digitalRead(input); | |
if (reading == 1) { | |
Serial.println("Start Beep"); | |
startBeep = millis(); | |
digitalWrite(relay, HIGH); | |
delay(500); | |
} | |
} else { | |
int now = millis(); | |
if (startBeep + beepLength < now) { | |
Serial.println("End Beep"); | |
startBeep = 0; | |
digitalWrite(relay, LOW); | |
delay(500); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment