Hi everybody,
I have a small project where with the help of 3 buttons i want to switch an RGBW led strip, so that one button turns on only the white leds, one button runs a continuous rgb colour switch loop and the third button to turns all the leds off.
i have managed to get the rgb colour switch working, but when i pust the button the colour switch runs only once and then it stays on at the last colour.
const int redPin = 9;
const int greenPin = 10;
const int bluePin = 11;
const int whitePin = 6;
const int whiteButton = 2;
const int colourButton = 3;
const int offButton = 4;
const int analogInPin0 = A0; // Analog input pin that the potentiometer is attached to
int wait = 400;
int colourButtonState = HIGH; // current state of the button
int reading;
int previous = LOW;
long time = 0; // the last time the output pin was toggled
long debounce = 200; // the debounce time, increase if the output flickers
void setup() {
pinMode(colourButton, INPUT);
}
void loop() {
reading = digitalRead(colourButton);
// if the input just went from LOW and HIGH and we've waited long enough
// to ignore any noise on the circuit, toggle the output pin and remember
// the time
if (reading == HIGH && previous == LOW && millis() - time > debounce) {
if (colourButtonState == HIGH)
colourButtonState = LOW;
else
colourButtonState = HIGH;
time = millis(); {
analogWrite(redPin, 255);
analogWrite(greenPin, 0);
analogWrite(bluePin, 0);
delay(wait);
analogWrite(redPin, 0);
analogWrite(greenPin, 255);
analogWrite(bluePin, 0);
delay(wait);
analogWrite(redPin, 0);
analogWrite(greenPin, 0);
analogWrite(bluePin, 255);
delay(wait);
analogWrite(redPin, 255);
analogWrite(greenPin, 255);
analogWrite(bluePin, 0);
delay(wait);
analogWrite(redPin, 80);
analogWrite(greenPin, 0);
analogWrite(bluePin, 80);
delay(wait);
analogWrite(redPin, 0);
analogWrite(greenPin, 255);
analogWrite(bluePin, 255);
delay(wait);
}
previous = reading;
}
}
Any help would be greatly appreciated!
Rolf102