Problem with ColorWipe using FastLED

Hey guys i seem to be having an issue with ColorWipe using FastLED, it literally wont wipe, all im getting from it is the whole strip setting to a color all at once, not the effect im wanting, could someone please look over my code and tell me what im doing wrong? Also the program calls for header file “Buttons.h” its included at the bottom.

#include "FastLED.h"
#include "Buttons.h"

#define DATA_PIN 0
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
#define NUM_LEDS 68

#define BRIGHTNESS 85
#define FRAMES_PER_SECOND 120

CRGB leds[NUM_LEDS];

const int interval = 25;
unsigned long previousMillis = millis();

void setup() {
 pinMode(BUTTON_LEAD, INPUT_PULLUP);
  FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  FastLED.setBrightness(BRIGHTNESS);
  }

void loop() {
  switch (mode) {
    case 1:
      colorWipe(0xff, 0x00, 0x00);
      break;

    case 2:
      colorWipe(0x00, 0xff, 0x00);
      break;

     case 3:
      colorWipe(0x00, 0x00, 0xff);
      break;

     default:
      mode = 1;
      break;
  }
  FastLED.show();
   
}

void colorWipe(byte red, byte green, byte blue){
  if(buttonListener()) { return; }
  if(millis() - previousMillis >= interval) {
      previousMillis = millis();
  for(int i=0; i<NUM_LEDS; i++){
    setPixel(i, red, green, blue);
  }
}
}

void setPixel(int Pixel, byte red, byte green, byte blue){
  leds[Pixel].r = red;
  leds[Pixel].g = green;
  leds[Pixel].b = blue;
}
#define BUTTON_LEAD 2

bool buttonState = LOW;
bool lastButtonState = LOW;
int mode = 1; //Default mode is one.

/* monitor button press */
bool buttonListener() {
  bool modeChanged = false;

  buttonState = digitalRead(BUTTON_LEAD);

  if (buttonState != lastButtonState) {
    if (buttonState == LOW) {
      mode++;
      modeChanged = true;
      delay(250);             // Debounce delay. I checked the best parameter and 250 was it.
    }
  }
  lastButtonState = buttonState;

  return modeChanged;
}
    for (int i = 0; i < NUM_LEDS; i++)
    {
      setPixel(i, red, green, blue);
    }

This sets each pixel to the same colour pretty much instantaneously so you will not see a wipe effect. As a test, add a delay() after the setPixel(). This is not the best way to do what you want but may provide a clue as to what is going on.

Also add a show call after the delay. You are setting all the LEDs before you actually show any of them. You only see a change when you call the show command.

Ok i cant use a delay because im using a pushbutton. Soon to be 2. But that would make sense im setting then all before they show. What do i need to change to fix that?

What do i need to change to fix that?

Do a show after each setPixel(). Use a delay() initially to prove what was wrong. In the longer term change to using millis() for timing after each show().

I tried moving the show after setting the pixels but it still wont work :/

Chrisrocks23:
I tried moving the show after setting the pixels but it still wont work :confused:

That is not what you were told to do. It was to delay and show after EACH pixel setting. Please post your code so we can see where you went wrong.

It should be something like this

for (int i = 0; i < NUM_LEDS; i++)
    {
      setPixel(i, red, green, blue);
      FastLED.show();
      delay(100);
    }

ok i did it with the delay and it works, this is what i have so far. But i need it to work using millis so i can change the colors. Little brother’s request lol.

#include "FastLED.h"
#include "Buttons.h"

#define DATA_PIN 0
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
#define NUM_LEDS 68

#define BRIGHTNESS 85
#define FRAMES_PER_SECOND 120

CRGB leds[NUM_LEDS];

const int interval = 25;
unsigned long previousMillis = millis();

void setup() {
 pinMode(BUTTON_LEAD, INPUT_PULLUP);
  FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  FastLED.setBrightness(BRIGHTNESS);
  }

void loop() {
  switch (mode) {
    case 1:
      colorWipe(0xff, 0x00, 0x00);
      break;

    case 2:
      colorWipe(0x00, 0xff, 0x00);
      break;

     case 3:
      colorWipe(0x00, 0x00, 0xff);
      break;

     default:
      mode = 1;
      break;
  }   
}

void colorWipe(byte red, byte green, byte blue){
  if(buttonListener()) { return; }
//  if(millis() - previousMillis >= interval) {
//      previousMillis = millis();
for(int i=0; i<NUM_LEDS; i++)
{
    setPixel(i, red, green, blue);
    FastLED.show();
    delay(100);
}
//}
}

void setPixel(int Pixel, byte red, byte green, byte blue){
  leds[Pixel].r = red;
  leds[Pixel].g = green;
  leds[Pixel].b = blue;
}

You then have to write the program as a state machine. It is a step up in complexity in code the idea is that the program runs in short little bursts. So there should be no for loops these should be replaced by code that keeps track of the loop variable and returns after just one iteration of it. This code is entered every x milliseconds depending on the speed you want it to.

Start of by getting your head round the concept by seeing my:- http://www.thebox.myzen.co.uk/Tutorial/State_Machine.html Or Robin2's several things at once http://forum.arduino.cc/index.php?topic=223286.0

Ok thanx :) ill be sure to read up on it!

I got this code to work for me but at the end when its supposed to wipe the other way to turn them off the last LED stays on and the modes wont switch anymore. But if i do a regular wipe forward it works fine. Any thoughts?

#include "FastLED.h"
#include "Buttons.h"

#define DATA_PIN 0
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
#define NUM_LEDS 67

#define BRIGHTNESS 85
#define FRAMES_PER_SECOND 120

CRGB leds[NUM_LEDS];

const int interval = 25;
unsigned long previousMillis = millis();

void setup() {
 pinMode(BUTTON_LEAD, INPUT_PULLUP);
  FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  FastLED.setBrightness(BRIGHTNESS);
  }

void loop() {
  switch (mode) {
    case 1:
      colorWipe(0xff, 0x00, 0x00);
      break;

    case 2:
      colorWipe(0x00, 0xff, 0x00);
      break;

     case 3:
      colorWipe(0x00, 0x00, 0xff);
      break;

     case 4:
      colorWipeOut(0x00, 0x00, 0x00);
      break;

     default:
      mode = 1;
      break;
  }   
}

void colorWipe(byte red, byte green, byte blue){
  if(buttonListener()) { return; }
  if(millis() - previousMillis >= interval) {
      previousMillis = millis();
for(int i=0; i<NUM_LEDS; i++)
{
    setPixel(i, red, green, blue);
    FastLED.show();
}
}
}


void colorWipeOut(byte red, byte green, byte blue){
  if(buttonListener()) { return; }
  if(millis() - previousMillis >= interval) {
      previousMillis = millis();
for(int i=NUM_LEDS; i>0; i--)
{
    setPixel(i, red, green, blue);
    FastLED.show();
}
}
}


void setPixel(int Pixel, byte red, byte green, byte blue){
  leds[Pixel].r = red;
  leds[Pixel].g = green;
  leds[Pixel].b = blue;
}

I haven’t been following but maybe try this.
for(int i=NUM_LEDS-1; i>=0; i–)

Thanx! Ill give it a shot. Im still a bit of a noob with the software and being sick doesnt help me much lol