Seems to me that it skips code

Simple Led rings doing colorWipe with no delay.
Runs like I expect it to with only a siingle line for each ring. When I enter a second colorWipe for each it seems to skip the first lines of code and only loop he second of each. I expect the first wipe to be slower than the second wipe for each ring.

#include <Adafruit_NeoPixel.h>

#define PIN 12
#define PIN2 13

// adjust this to use the correct pin
Adafruit_NeoPixel strip = Adafruit_NeoPixel(14, PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(14, PIN2, NEO_GRB + NEO_KHZ800);
void setup() {
  Serial.begin(115200);
  strip.begin();
  strip2.begin();
  strip.setBrightness(10);
  strip2.setBrightness(10);
  strip.show();
  strip2.show();
}

void loop() {

  colorWipe(strip.Color(0, 255, 0), 100);
  colorWipe2(strip2.Color(0, 0, 255), 100);

  colorWipe(strip.Color(0, 255, 0), 25);
  colorWipe2(strip2.Color(0, 0, 255), 25);
}

void wipe() {  // clear all LEDs
  for (int i = 0; i < strip.numPixels(); i++) {
    strip.setPixelColor(i, strip.Color(0, 0, 0));
  }
}

void wipe2() {  // clear all LEDs
  for (int i = 0; i < strip2.numPixels(); i++) {
    strip2.setPixelColor(i, strip2.Color(0, 0, 0));
  }
}

/*
  colorWipe
  In:
    desired color
    wait time between updates
  Returns:
    true if colorWipe in progress, else false
*/
bool colorWipe(uint32_t color, unsigned int wait) {
  // keep track of which pixel needs to be updated
  static byte pixelNum;
  // remember if we are in progress
  static bool inProgress = false;
  // last time that a pixel was updated
  static uint32_t lastUpdateTime;

  // if first time for a cycle
  if (inProgress == false) {
    lastUpdateTime = millis();
    // indicate that one cycle is complete
    inProgress = true;
  }

  if (pixelNum == 0 || millis() - lastUpdateTime >= wait) {
    lastUpdateTime = millis();

    // update the pixel
    strip.setPixelColor(pixelNum, color);

    strip.show();

    // next time, next pixel
    pixelNum++;
    // if we have reached the number of pixels
    if (pixelNum >= strip.numPixels())

    {
      // reset pixelNum
      pixelNum = 0;
      // indicate that one cycle is complete
      inProgress = false;
      wipe();
    }
  }

  // indicate to caller the status of the colorWipe cycle
  return inProgress;
}

bool colorWipe2(uint32_t color, unsigned int wait) {
  // keep track of which pixel needs to be updated
  static byte pixelNum;
  // remember if we are in progress
  static bool inProgress = false;
  // last time that a pixel was updated
  static uint32_t lastUpdateTime;

  // if first time for a cycle
  if (inProgress == false) {
    lastUpdateTime = millis();
    // indicate that one cycle is complete
    inProgress = true;
  }

  if (pixelNum == 0 || millis() - lastUpdateTime >= wait) {
    lastUpdateTime = millis();

    // update the pixel

    strip2.setPixelColor(pixelNum, color);

    strip2.show();
    // next time, next pixel
    pixelNum++;
    // if we have reached the number of pixels

    if (pixelNum >= strip2.numPixels()) {
      // reset pixelNum
      pixelNum = 0;
      // indicate that one cycle is complete
      inProgress = false;
      wipe2();
    }
  }

  // indicate to caller the status of the colorWipe cycle
  return inProgress;
}

You forgot show()' after your wipes.

Wait, no.. There's more code down there.

Something to look at..
Async Leds..

good luck.. ~q

I think your program can be much simpler.

This simulation of a similar idea to yours uses a different library, but you can see how two simultaneous color wipes do not need to take many lines of code.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.