Problem lighting neopixel 'backwards'

Please help!

I have a Nano IoT 33 with two neopixel strips attached.

Strip A has 72 LEDs
Strip B has 21 LEDs

Strip B lights as expected, however, I am attempting to get strip A to light from both ends. Currently I only seem to be able to get the count up to work on strip A.

// Simple demonstration on using an input device to trigger changes on your
// NeoPixels. Wire a momentary push button to connect from ground to a
// digital IO pin. When the button is pressed it will change to a new pixel
// animation. Initial state has all pixels off -- press the button once to
// start the first animation. As written, the button does not interrupt an
// animation in-progress, it works only when idle.

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
 #include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif

#include <WiFiNINA.h>

// Digital IO pin connected to the button. This will be driven with a
// pull-up resistor so the switch pulls the pin to ground momentarily.
// On a high -> low transition the button press logic will execute.
#define BUTTON_PIN   2

#define PIXEL_PIN_A    12  // Digital IO pin connected to the NeoPixels.
#define PIXEL_PIN_B    10  // Digital IO pin connected to the NeoPixels.

#define PIXEL_COUNT 72  // Number of NeoPixels

// Declare our NeoPixel strip object:
Adafruit_NeoPixel stripa(PIXEL_COUNT, PIXEL_PIN_A, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel stripb(PIXEL_COUNT, PIXEL_PIN_B, NEO_GRB + NEO_KHZ800);
// Argument 1 = Number of pixels in NeoPixel strip
// Argument 2 = Arduino pin number (most are valid)
// Argument 3 = Pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
//   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)

//please enter your sensitive data in the Secret tab
char ssid[] = "YellowAjah";                // your network SSID (name)
char pass[] = "xxx";                // your network password (use for WPA, or use as key for WEP)
int status = WL_IDLE_STATUS;             // the Wi-Fi radio's status

boolean oldState = HIGH;
int     mode     = 0;    // Currently-active animation mode, 0-9
int     j       = 0;
void setup() {

  // attempt to connect to Wi-Fi network:
  while (status != WL_CONNECTED) {
    // Connect to WPA/WPA2 network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }

  pinMode(BUTTON_PIN, INPUT_PULLUP);
  stripa.begin(); // Initialize NeoPixel strip object (REQUIRED)
  stripa.show();  // Initialize all pixels to 'off'
  stripb.begin(); // Initialize NeoPixel strip object (REQUIRED)
  stripb.show();  // Initialize all pixels to 'off'
}

void loop() {
  // Get current button state.
  boolean newState = digitalRead(BUTTON_PIN);

  // Check if state changed from high to low (button press).
  if((newState == LOW) && (oldState == HIGH)) {
    // Short delay to debounce button.
    delay(20);
    // Check if button is still low after debounce.
    newState = digitalRead(BUTTON_PIN);
    if(newState == LOW) {      // Yes, still low
      if(++mode > 2) mode = 0; // Advance to next mode, wrap around after #2
      switch(mode) {           // Start the new animation...
        case 0:
          colorWipe(stripa.Color(  0,   0,   0), 50);    // Black/off
          colorWipe(stripb.Color(  0,   0,   0), 50);    // Black/off
          break;
        case 1:
          colorWipe(stripa.Color(255,139,39), 50);    // Dim
          colorWipe(stripb.Color(255,139,39), 50);    // Dim
          break;
        case 2:
          colorWipe(stripa.Color(  255, 255,   255), 50);    // Bright
          colorWipe(stripb.Color(  255, 255,   255), 50);    // Bright
          break;
      }
    }
  }

  // Set the last-read button state to the old state.
  oldState = newState;
}

// Fill strip pixels one after another with a color. Strip is NOT cleared
// first; anything there will be covered pixel by pixel. Pass in color
// (as a single 'packed' 32-bit value, which you can get by calling
// strip.Color(red, green, blue) as shown in the loop() function above),
// and a delay time (in milliseconds) between pixels.
void colorWipe(uint32_t color, int wait) {
  for(int i=0; i<stripa.numPixels(); i++) { // For each pixel in strip...
    stripa.setPixelColor(i, color);         //  Set pixel's color (in RAM)
    stripa.setPixelColor((72 - i), color);         //  Set pixel's color (in RAM)
    stripa.show();                          //  Update strip to match
    if(i < 22) {
        stripb.setPixelColor(i, color);         //  Set pixel's color (in RAM)
        stripb.show();                          //  Update strip to match
    }
    delay(wait);                           //  Pause for a moment
  }
}

Can anyone give me some pointers on where I am going wrong, please?

Thanks,

GlennCannon

so why do you define both with 72 LEDs ?

Good point. I'll update the PIXEL_COUNT for strip B. However, I am not sure that will help with the strip A issue

// Simple demonstration on using an input device to trigger changes on your
// NeoPixels. Wire a momentary push button to connect from ground to a
// digital IO pin. When the button is pressed it will change to a new pixel
// animation. Initial state has all pixels off -- press the button once to
// start the first animation. As written, the button does not interrupt an
// animation in-progress, it works only when idle.

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif

#include <WiFiNINA.h>

// Digital IO pin connected to the button. This will be driven with a
// pull-up resistor so the switch pulls the pin to ground momentarily.
// On a high -> low transition the button press logic will execute.
#define BUTTON_PIN   2
#define PIXEL_PIN_A    12  // Digital IO pin connected to the NeoPixels.
#define PIXEL_PIN_B    10  // Digital IO pin connected to the NeoPixels.
#define PIXEL_COUNT 72  // Number of NeoPixels

// Declare our NeoPixel strip object:
Adafruit_NeoPixel stripa(PIXEL_COUNT, PIXEL_PIN_A, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel stripb(21, PIXEL_PIN_B, NEO_GRB + NEO_KHZ800);

//please enter your sensitive data in the Secret tab
char ssid[] = "YellowAjah";                // your network SSID (name)
char pass[] = "xxx";                // your network password (use for WPA, or use as key for WEP)
int IDLEstatus = WL_IDLE_STATUS;             // the Wi-Fi radio's status

boolean oldState = HIGH;
int     mode     = 0;    // Currently-active animation mode, 0-9
int     j       = 0;

void setup() {
  // attempt to connect to Wi-Fi network:
  while (IDLEstatus != WL_CONNECTED) {
    // Connect to WPA/WPA2 network:
    IDLEstatus = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }

  pinMode(BUTTON_PIN, INPUT_PULLUP);
  stripa.begin(); // Initialize NeoPixel strip object (REQUIRED)
  stripa.show();  // Initialize all pixels to 'off'
  stripb.begin(); // Initialize NeoPixel strip object (REQUIRED)
  stripb.show();  // Initialize all pixels to 'off'
}

void loop() {
  // Get current button state.
  boolean newState = digitalRead(BUTTON_PIN);

  // Check if state changed from high to low (button press).
  if ((newState == LOW) && (oldState == HIGH)) {
    oldState = newState;
    // Short delay to debounce button.
    delay(20);
    // Check if button is still low after debounce.
    if (newState == LOW) {     // Yes, still low
      switch (mode) {          // Start the new animation...
        case 0:
          colorWipe(stripa.Color(  0,   0,   0), 50);    // Black/off
          colorWipe(stripb.Color(  0,   0,   0), 50);    // Black/off
          break;
        case 1:
          colorWipe(stripa.Color(255, 139, 39), 50);  // Dim
          colorWipe(stripb.Color(255, 139, 39), 50);  // Dim
          break;
        case 2:
          colorWipe(stripa.Color(  255, 255,   255), 50);    // Bright
          colorWipe(stripb.Color(  255, 255,   255), 50);    // Bright
          break;
      }
      if (++mode > 2) mode = 0; // Advance to next mode, wrap around after #2
    }
  }

  // Set the last-read button state to the old state.
}

// Fill strip pixels one after another with a color. Strip is NOT cleared
// first; anything there will be covered pixel by pixel. Pass in color
// (as a single 'packed' 32-bit value, which you can get by calling
// strip.Color(red, green, blue) as shown in the loop() function above),
// and a delay time (in milliseconds) between pixels.
void colorWipe(uint32_t color, int wait) {
  for (int i = 0; i < stripa.numPixels(); i++) { // For each pixel in strip...
    stripa.setPixelColor(i, color);         //  Set pixel's color (in RAM)
    stripa.setPixelColor((71 - i), color);         //  Set pixel's color (in RAM)
    stripa.show();                          //  Update strip to match
    if (i < 22) {
      stripb.setPixelColor(i, color);         //  Set pixel's color (in RAM)
      stripb.show();                          //  Update strip to match
    }
    delay(wait);                           //  Pause for a moment
  }
}

So I have fixed the declaration of the number of pixels in each string. However, I still cannot get string A to light from the highest number down.

Any ideas?

void colorDown(uint32_t color, int wait) {
  for (int i = 0; i < stripa.numPixels(); i++) { // For each pixel in strip...
    
    stripa.setPixelColor((71 - i), color);         //  Set pixel's color (in RAM)
    stripa.show();                          //  Update strip to match
    
      
    
    delay(wait);                           //  Pause for a moment
  }
}

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