OK, figured it all out. I think it could be more simple though.
heres what i came up with
const int trigger = 2;
const int modeButton = 4;
const int rled = 9;
const int gled = 10;
const int bled = 11;boolean lastButton = LOW;
boolean currentButton = LOW;int colorStep = 0;//Color identifier
int modeStep = 0;//Mode identifier
int dimmingTimer = 2; //Timer for dimming, higher = longer//Debouce function
boolean debounce(boolean last)
{
boolean current = digitalRead(modeButton);
if (last != current)
{
delay(5);
current = digitalRead(modeButton);
}
return current;
}void setup ()
{
pinMode (trigger, INPUT);
pinMode (modeButton, INPUT);
pinMode (rled, OUTPUT);
pinMode (gled, OUTPUT);
pinMode (bled, OUTPUT);
}void loop()
{
if (colorStep > 3) colorStep = 0;
if (colorStep == 0) //White
if (digitalRead (trigger) == HIGH)
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=1)
{
// sets the value (range from 0 to 255):
analogWrite(rled, fadeValue);
analogWrite(gled, fadeValue);
analogWrite(bled, fadeValue);
// wait time between dimming steps
delay (dimmingTimer);
if (fadeValue == 0) colorStep ++;
}
if (colorStep == 1) //Red
if (digitalRead (trigger) == HIGH)
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=1)
{
// sets the value (range from 0 to 255):
analogWrite(rled, fadeValue);
// wait time between dimming steps
delay (dimmingTimer);
if (fadeValue == 0) colorStep ++;
}
if (colorStep == 2) //Green
if (digitalRead (trigger) == HIGH)
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=1)
{
// sets the value (range from 0 to 255):
analogWrite(gled, fadeValue);
// wait time between dimming steps
delay (dimmingTimer);
if (fadeValue == 0) colorStep ++;
}
if (colorStep == 3) //Blue
if (digitalRead (trigger) == HIGH)
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=1)
{
// sets the value (range from 0 to 255):
analogWrite(bled, fadeValue);
// wait time between dimming steps
delay (dimmingTimer);
if (fadeValue == 0) colorStep = 0;
}
}