wow what a mess...
anyways what I think i did to your code was move the initial truning on of the led outside of the loop, then set up a led state variable (probably a terrible way to do it ram wise) and then every time counter >= 500 we toggle the ledstate and write the ledstate to ledon
(~ledstate)&HIGH should do the business, bitwise inversion of ledstate, taking only the HIGH bit...
#define BLEEDERS 0 //define IO
#define TRIAC 1
#define BYPASS 2
#define LEDON 3
#define BUTTON 4
#define TEMP1 5
#define TEMP2 6
const int LOWER_BOUND = 87;
const int UPPER_BOUND = 115;
int val = 0;
boolean lightsOn = false; // state variables
boolean lastButton = LOW; // Variable containing the previous button state.
boolean currentButton = LOW; // Variable containing the current button state.
int whichLED = 0;
int counter = 0; // main counter
void setup()
{
pinMode(BLEEDERS, OUTPUT); // set up IO
pinMode(TRIAC, OUTPUT);
pinMode(BYPASS, OUTPUT);
pinMode(LEDON, OUTPUT);
pinMode(BUTTON, INPUT);
pinMode(TEMP1, INPUT);
pinMode(TEMP2, INPUT);
}
/*
* Debouncing function
* Pass it to previous button state,
* and get back the current debounced button state.
*/
boolean debounce (boolean last)
{
boolean current = digitalRead (BUTTON); // Read the button state
if (last != current) // if it's different...
{
delay (10); // wait 10ms
current = digitalRead (BUTTON); // read it again
return current; // return the current value.
}
}
void loop ()
{
currentButton = debounce (lastButton); // read debounced state
if (lastButton == LOW && currentButton == HIGH) // if it was pressed...
{
lightsOn = ! lightsOn;
} // toggle the LED value
lastButton = currentButton; // reset button value
digitalWrite (whichLED, lightsOn); // change the LED state
digitalWrite (LEDON, lightsOn);
if (lightsOn == false) // turn LED off and clean up
{
counter = 0;
digitalWrite(BLEEDERS, LOW);
digitalWrite(TRIAC, LOW);
digitalWrite(BYPASS, LOW);
digitalWrite(LEDON, LOW);
whichLED = 0;
}
else // Or if we are activating LEDs
{
digitalWrite(whichLED, HIGH); // Turn first LED on to start
digitalWrite(LEDON, HIGH);
}
if (lightsOn == true) // Manage LED state
{
counter++; // Increment counter
if (counter >= 500) // ~ 1 second has passed
{ // So increment LED state
counter = 0;
digitalWrite(whichLED, HIGH); //
whichLED++;
if (whichLED > 2) // Don't let whichLED go to invalid state
whichLED = 2;
}
}
delay(1); // 1 ms delay for 1000 count = ~ 1 second
val=analogRead (TEMP1); // Read the TEMP1 sensor
if (val >= UPPER_BOUND) // If value is higher than upper bound
{
if (lightsOn) // and OUTPUTs are ON
{
counter = 0; // shut everything OFF and clear the counter
digitalWrite (BLEEDERS, LOW);
digitalWrite (TRIAC, LOW);
digitalWrite (BYPASS, LOW);
digitalWrite (LEDON, LOW);
lightsOn = false;
}
}
else
{
lightsOn == true; // Otherwise, toggle button, ON - OFF
}
val=analogRead (TEMP1); // Read the TEMP1 sensor
if (val > UPPER_BOUND) //If value is higher than upper bound...
{
if (! lightsOn) //...and if outputs were shut OFF by TEMP1 sensor
{
int ledstate= HIGH;
digitalWrite(LEDON, ledstate);
do
{
lightsOn = false; // turn all outputs OFF
val=analogRead (TEMP1); // and read the TEMP1 sensor again
counter++; // I WANT THE "LED" TO BLINK
if (counter >= 500) // USING counter INSTEAD OF delay()
{ //
counter = 0;
ledstate = (~ledstate)&HIGH; //toggle ledstate
digitalWrite(LEDON, ledstate); //
}
}
while (val > LOWER_BOUND); // keep all outputs OFF during the time when value is
} // above lower bound, BUTTON is disabled
}
else
{
lightsOn == true; // Otherwise, toggle button, ON - OFF
}
val=analogRead (TEMP2); //Read the TEMP2 sensor
if (val >= UPPER_BOUND) //If value is higher than upper bound
{
if (lightsOn) // and OUTPUTs are ON
{
counter = 0;
digitalWrite (BLEEDERS, LOW); //shut everything OFF and clear the counter
digitalWrite (TRIAC, LOW);
digitalWrite (BYPASS, LOW);
lightsOn = false;
}
}
else
{
lightsOn == true; // Otherwise, toggle button, ON - OFF
}
val=analogRead (TEMP2); // read the TEMP2 sensor
if (val > UPPER_BOUND) // if value is higher than upper bound...
{
if (! lightsOn) //...and if outputs were shut OFF by TEMP2 sensor
{
do
{
lightsOn = false; // turn all outputs OFF
val=analogRead (TEMP2); // and read the TEMP2 sensor again
}
while (val > LOWER_BOUND); // keep all outputs OFF during the time when value is
} // above lower bound, BUTTON is disabled
}
else
{
lightsOn == true; // Otherwise, toggle button, ON - OFF
}
}