[SOLVED] Problem with Arrays?

Hi

I'm new at this and wanted to get startet with some lights....
So I have a Nano and a 12 bit nanopixel ring.

I can set the ring to any colors I want. Make them move around and got the basics.
But I wanted to clean up the code and there for I defined a few colors

#include <Adafruit_NeoPixel.h>

#define PIN 6
int ArrayLength;
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 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)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(12, PIN, NEO_GRB + NEO_KHZ800);

// Define colors
uint32_t black = strip.Color(0, 0, 0);
uint32_t red = strip.Color(255, 0, 0);
uint32_t green = strip.Color(0, 255, 0);
uint32_t blue = strip.Color(0, 0, 255);
uint32_t yellow = strip.Color(255, 255, 0);
uint32_t aqua = strip.Color(0, 255, 255);
uint32_t magenta = strip.Color(255, 0, 255);
uint32_t white = strip.Color(255, 255, 255);

And a Array with the colors:

//Define color array
int ColorArray[] = {black, red, green, blue, yellow, aqua, magenta, white};

And ofcause some code to use it:

void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}

void loop() {
for (ArrayLength = 0; ArrayLength < 8; ArrayLength = ArrayLength + 1) {
NEOcounter = 11;
ColorloopCounter();
}
}

void ColorloopCounter() {
do {
strip.setPixelColor(NEOcounter, ColorArray[ArrayLength]);
strip.show();
--NEOcounter;
delay(500);
while (NEOcounter >= 0);
}

And it works but never shows RED. Colors containing RED are showed but without the red element. And for RED that is the same as no light.

I've tried:

strip.setPixelColor(NEOcounter, ColorArray[1]);

And it dosn't work.

But

//strip.setPixelColor(NEOcounter, red);

Does work.

All colors not containing a RED element does display correctly.

What am I doing wrong.
It's as if the first value of the uint32_t red = strip.Color(255, 0, 0); declaration is set to 0.

Kind regards Jgaard

You make colours as uint32_t type but the array that holds them is only an int type.

aarg:
You make colours as uint32_t type but the array that holds them is only an int type.

Makes good sence but why does it work for BLUE and GREEN then?

thusgaard:
Makes good sence but why does it work for BLUE and GREEN then?

Read the source code for strip.Color().

Thank you for helping.

It's about how the colours are stored in a variable. Green and blue are likely stored in the low 16 bits.

thusgaard:
Makes good sence but why does it work for BLUE and GREEN then?

Because when you jam a 32-bits into a 16-bit number, the top 16 bits get lopped off. When you expand that back out to 32 bits, the compiler just fills it in with zeros. In your particular application, RED is stored at bits 16-23, and that's what's going missing.