(deleted)
Can't you just put your existing code, the stuff in loop(), inside an "if" which will look to see of the button is pressed?
void loop()
{
if(digitalRead(theButton) == LOW) //assuming a button to ground with pullups enabled
{
// all the existing stuff from loop() here
}
}
And add an else which turns the stuff off.
It matters not that it will be off already most of the time, turning it off again is not going to do anything bad.
(deleted)
Crap, my bad....
Lose the ; at the end of the "if"
if(digitalRead(theButton) == LOW); // <<<<<<<<<<<<<<< lose the ;
Sorry....
edit... not my bad after all, wasn't in my example earlier
(deleted)
You'll make your life much easier if you write a simple sketch just to do the button thing, without all the ifs and buts about temperature.
Just try something like this:
void loop()
{
if(digitalRead(theButton) == LOW) //pressed
{
//switch the LED on
}
else // not pressed
{
//switch the LED off
}
} //loop
Get that sorted then bung the other stuff back in, imo.
So at the end where the 'else' is placed, it asked for a ';' so placed it there,
Wrong there should not be a ; after the else.
After the else should be a { then on a new line your line to turn things off with a ; on the end of that. Then on the next line there should be a }
Then on the next line there should be a } to mark the end of the function.
(deleted)
Read what I say.
After the else there should be a { you did not do that did you?
else {
analogWrite(red, 0);
analogWrite(green, 0);
analogWrite(blue, 0);
}
}
Also what do you think...l. else (digitalRead(theButton) == HIGH)
Is doing? Did you mean
else if(digitalRead(theButton) == HIGH)
If so there is no need for it because you never get to the else without without it being high already.