I have a simple sketch that I want to light an LED strip when a sensor is activated. This first time the sensor is activated, I want the lights to turn red, the next time green and the next time blue. I created a simple counter using the following code, but it's not working right. At the beginning of the loop, I check to see if the counter is equal to 4 and if it is, I set it back down to 0.
When the counter equals 1 - I want the "red" code loop to play, when the counter equals 2, i want the green loop to play, etc...
I thought my logic below was sound, but it just cycles through all the loops when the sensor is activated. I printed the value of the counter to try and troubleshoot, but it only prints 0.
void loop()
{
if(digitalRead(sensor)==HIGH)
{
if (counter=4) {
counter =0;
}
Serial.println(counter);
counter = counter++;
digitalWrite(ledPin, HIGH);
strip.setBrightness(50);
if (counter=1){
red(); }
if (counter=2){
green(); }
if (counter=3){
blue(); }
}
Any help would be appreciated.