Hello all,
I have been working on an RGB LED controller. I thought I had it figured out, but I do not. I have a basic sketch written. The problem I am having is when P5, colorSlectPB, goes HIGH the LEDS are not changing color. Pretty sure its my code. Also is there a way to have the DigiSpark retain the value of a valaiable, colorSelectcount, after power loss?
int colorSelectPB = 5;
int redPin = 0;
int bluePin = 4;
int greenPin = 1;
boolean lastButton = LOW;
boolean currentButton = LOW;
int colorSelectcount = 0;
void setup()
{
pinMode(colorSelectPB, INPUT);
//Serial.begin(9600);
}
boolean debounce(boolean last)
{
boolean current = digitalRead(colorSelectPB);
if (last != current)
{
delay(5);
current = digitalRead(colorSelectPB);
}
return current;
}
void loop()
{
//Serial.println (colorSelectcount);
currentButton = debounce(lastButton);
if (lastButton == LOW && currentButton == HIGH)
{
colorSelectcount++;
lastButton = currentButton;
}
if (colorSelectcount == 1) //RED
{
analogWrite (redPin, 255);
analogWrite (bluePin, 0);
analogWrite (greenPin, 0);
}
if (colorSelectcount == 2) //BLUE
{
analogWrite (redPin, 0);
analogWrite (bluePin, 255);
analogWrite (greenPin, 0);
}
if (colorSelectcount == 3) //GREEN
{
analogWrite (redPin, 0);
analogWrite (bluePin, 0);
analogWrite (greenPin, 255);
}
if (colorSelectcount == 4) //ORANGE
{
analogWrite (redPin, 255);
analogWrite (bluePin, 20);
analogWrite (greenPin, 255);
}
if (colorSelectcount == 5) //PURPLE
{
analogWrite (redPin, 102);
analogWrite (bluePin, 0);
analogWrite (greenPin, 102);
}
if (colorSelectcount == 6) //AQUA
{
analogWrite (redPin, 0);
analogWrite (bluePin, 255);
analogWrite (greenPin, 255);
}
if (colorSelectcount == 7) //YELLOW
{
analogWrite (redPin, 255);
analogWrite (bluePin, 255);
analogWrite (greenPin, 0);
}
if (colorSelectcount == 8) //WHITE
{
analogWrite (redPin, 255);
analogWrite (bluePin, 255);
analogWrite (greenPin, 255);
}
if (colorSelectcount > 8) colorSelectcount = 1;
else
{
analogWrite (redPin, 0);
analogWrite (bluePin, 0);
analogWrite (greenPin, 0);
}
}
Thank you,
Micheal