Here is the code which i written.But am still confused about the ack function.
/*
alarm with Acknowledge
If the input turns 0 to 1 o/p led blinks with the common buzzer o/p.if ack i/p (push button) pressed the buzzer will mute.
but if the second alarm triggered buzzer will get activated again.
*/
const int ack= 6;
const int buzzer = 9;
const int input1=2;
const int input2=3;
const int led1=7;
const int led2=8;
You snippet of code does not provide enough information as to how you tried to use state change detection so please post the full program or a shorter but complete example of the problem.
The principle is simple. Read the input and if it is different than last time it was read and is now in the state that indicates that it has become activated then do something. Each time you read the input save it before reading it again so that you can detect the next time it changes.
Could you please give the ack code for me am stuck with that doing lot of stupid things.
see the code
/*
alarm with reset. if the input turns 0 to 1 o/p led blinks with the common buzzer o/p.if reset i/p (push button) pressed the buzzer will mute.
but if the second alarm triggered buzzer will get activated again.
*/
const int reset= 6;
const int buzzer = 9;
const int input1=2;
const int input2=3;
const int led1=7;
const int led2=8;
int S1;
int S2;
int buttonState = 0;
int lastButtonState = 0;
int ack;
void setup() {
pinMode (input1,INPUT);
pinMode (input2,INPUT);
pinMode (reset,INPUT);
pinMode (led1,OUTPUT);
pinMode (led2,OUTPUT);
pinMode (buzzer,OUTPUT);
}
void loop() {
buttonState = digitalRead(reset);
if (buttonState != lastButtonState) {
digitalWrite (ack,HIGH);
lastButtonState = buttonState;
}
if
(lastButtonState = buttonState)
digitalWrite (ack,LOW);
S1=digitalRead(input1);
S2=digitalRead(input2);
if (S1==HIGH )
{
digitalWrite (led1,HIGH);
delay(500);
digitalWrite (led1,LOW);
delay(500);
digitalWrite (led1,HIGH);
}
else
{
digitalWrite (led1,LOW);
}
if
(S2==HIGH )
{
digitalWrite (led2,HIGH);
delay(500);
digitalWrite (led2,LOW);
delay(500);
digitalWrite (led2,HIGH);
}
else
{
digitalWrite (led2,LOW);
}
if
(S1==HIGH || S2==HIGH){
if (ack=LOW){
digitalWrite(buzzer,HIGH);
}
}}
when the next time the arduino scan the code buzzer will be activate again.
No it won't. If the code is written properly the buzzer will not be activated until the input changes to the activated state again. The code needs to look for the state change not just the fact that the input is in a particular state.