I'm novice on arduinos. I'm building an alarm circuit with a relay works with Arduino Uno R3. I'm using this code that I attached on this message. But I don't know what I should write additional codes to this file for stopping alarm with an button on number 9 pin? Help me please.
if(ahours == hours && amins == mins && amins != 0)
{
if (digitalRead(9) == LOW) //it means the alarm relay can only be HIGH if the button 9 is not press (LOW state), if button 9 is being pressing the alarm relay can not be HIGH, so that disable the alarm
{
digitalWrite(relay, HIGH);
}
}
Changing the value of ahours and/or amins when the switch IS pressed is a crappy idea. Changing the value when the switch BECOMES pressed is a much better idea. The state change detection example shows how to do that.
You appear to already have a switch on pin 9 that has nothing to do with stopping an alarm. You have NO comments in the code that explain that the hell is connected to what.
You seem to have some foolish idea that dividing an unsigned long by 1000 will result in a value that will always fit in an int. Dream on.
I don't see anything in the code that indicates that there is an alarm, not even some comments. So, stopping the non-existent alarm doesn't seem necessary.
PS: Your code looks like it was typed by a drunken monkey. Use Tools + Auto Format, and get that monkey into rehab.