I'm trying to biuild a countdown timer with 12 WS2812 ring.

I’m trying to biuild a countdown timer with 12 WS2812 ring. Initial code using Delay() worked Ok but now trying using millis() based on the BlinkWithout Delay tutorial. I want an action at n millis intervals and the logic works eg I can get a message “Yes” to the serial monitor every n millis (i’ll develop the code for the countdown whn i gert this working) but when I add fast LED code I cannot get the LEDS to run the two colourschemes at the same n millis. When I upload it the 1st LED glows brighly and some but not all the rest illuminatee but there is no change between the two states despite the serial message responding correclty. Not sure if I shoul post code here but here goes: All help greatefully received

#include <FastLED.h>

#define NUM_LEDS 12
#define DATA_PIN 1
CRGB leds[NUM_LEDS];

unsigned long StartMillis(millis());
unsigned long LED_On(2000);
unsigned long CurrentMillis;
int counter;

void setup() {

FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
FastLED.setBrightness (32);

StartMillis = millis();
Serial.begin(9600);
Serial.println(StartMillis);
}

void loop() {

CurrentMillis = millis();
Serial.print(“Start”);
Serial.println(StartMillis);
Serial.println(“Current”);
Serial.println(CurrentMillis);

if(CurrentMillis-StartMillis >= LED_On * counter)
{
Serial.println(“Yes”);
//set LED colourscheme
leds[0] = CRGB::Black;
leds[1] = CRGB::Red;
leds[2] = CRGB::Red;
leds[3] = CRGB::Red;
leds[4] = CRGB::Black;
leds[5] = CRGB::Yellow;
leds[6] = CRGB::Yellow;
leds[7] = CRGB::Black;
leds[8] = CRGB::Green;
leds[9] = CRGB::Green;
leds[10]= CRGB::Green;
leds[11]= CRGB::Green;

  FastLED.show(); //turn on all LEDS 

delay(2000);
Serial.println(“Yes”);
//Serial.println(CurrentMillis-StartMillis);
counter = counter +1;
}

}

I don’t see two states in your code, you only set it to a specific pattern (after printing “Yes”) and never change anything. There is no second state.

Hello @Tony_Ray Please put code on http://gist.github.com and share the link here. G+ can mess the code up. Also line numbers can be referenced in discussion and the code can more easily be viewed on mobile devices.

Your first pixel shouldn’t light up at all since you’re setting it to black, but you mention the first pixel is glowing red. So I’d like to confirm, does the strip light up correctly when running some of the FastLED example sketches?

Are things wired up correctly?

Hi Kirill - thanks i have corrected that an I can confim that the LED ring works correct;y with a simple FastLED sketch and with a complex Adafruit demo.

I have posted the code as Marc suggests here.

@Tony_Ray ok, now you set it to specific colors, when check the condition and immediately set to other colors. The problem here is “immediately”. It looks like this now (pseudocode):

set colors1;
show();
if (condition) {
set colors2;
show();
delay();
}

See, there is no delay between colors1 and colors2, so all you see is colors2.

I guess you wanted something like this (pseudocode):

if (condition) {
set colors2;
} else {
set colors1;
}
show();
delay();

Hi Kirill sorry for not getting back sooner. I’ll make suggested code changes and report back

@Tony_Ray Hi I have discoverered that its the Serial monitoring that is interfering when I take that off I can swap between two states.