I need to create a climate control system, So far it gets the temperature switches different leds on depending on the temp and pulses a fan at different speeds also depending on the temp. If it goes above a certain temp it will sound an alarm using a piezo buzzer and only operates when the light is at a sufficient level(defined by me).
What i have to do now is create an alarm reset code using button pushes e.g 3 button pushes in succession that disables the alarm for 5 seconds. i tried by inserting a function in my code to read the state of the button. But unless i get the timing exactly right and press the button when the arduino attempts to read the state either HIGH or LOW it wont work.
Resulting in me mashing the button and then 10secs later it reads the button. Any ideas would be greatly appreciated?
here is a snippet of the code im having trouble with

if ( temp <= 303) // if temp is less than 30deg celcius switch on all three leds and pulse the fan
{
digitalWrite(LED1 ,HIGH);
digitalWrite(LED2 ,HIGH);
digitalWrite(LED3 ,HIGH);
sysState=1;
digitalWrite(fanPin, HIGH);
delay(250);
digitalWrite(fanPin, LOW);
delay(250);
}
else // if temp was not less than 30deg setalarm()
setAlarm();
}
else
{
Serial.println("Lights are off or too dim to operate"); // test to see if light levels are sufficient
sysState = 0;
digitalWrite(LED1 ,LOW);
digitalWrite(LED2 ,LOW);
digitalWrite(LED3 ,LOW);
}
}
void setAlarm()
{
long frequency = 523; //C5 tone frequency in HZ.
long length = 1000; // Required tone length in milliseconds
long delayValue = 1000000/frequency/2;
long numCycles = frequency * length/1000;
if(alarmState=1) // alarm state is 1 by default
{
Serial.println("Alarm!!");
for (long i=0; i < numCycles; i++)
{
digitalWrite(speakerPin,HIGH);
delayMicroseconds(delayValue);
digitalWrite(speakerPin,LOW);
delayMicroseconds(delayValue);
}
}
else
Serial.println("You Have diasbaled the alarm"); // if alarm state is not 1 then alarm must have been disable
}
void buttonStuff() // here is where i dont know what to do!!!!!!!!
{
Serial.println("Press the button once to ");
delay(250);
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH)
{
alarmState=0; // set alarm state to 0 therefore it will skip over the setAlarm() function and print a message saying alarm has been disabled.
Serial.println("Alarm OFF");
}
}
I was first just trying to disabled the alarm completely until i could read the button state properly.