Go Down

Topic: Incorrect display color when using matrix.Color  (Read 560 times) previous topic - next topic

cwduffy01

Hello, everyone.

I am encountering some difficulties when using the matrix.Color() function in the Adafruit Neopixel Library. Whenever I use it in different functions, such as matrix.setPixelColor(), it displays a different color than intended. For example, if I set uint32_t color to matrix.Color(255, 255, 255), the intended color is obviously white, but the Neopixel ends up displaying (0, 255, 255). It seems as if all of the values of the intended RGB tuple are shifted to the right one, so matrix.Color(0, 255, 0) will end up displaying (0, 0, 255) instead.

A sample of my code is attached below.

I would appreciate any and all help given. Thank you!

Code: [Select]

uint32_t color=matrix.Color(255, 255, 255);
 
void setup()
{
  matrix.begin();
  matrix.setBrightness(5);
}

void loop()
{
  matrix.setPixelColor(0, color);
  matrix.show();
  delay(100);
}

Grumpy_Mike

Quote
It seems as if all of the values of the intended RGB tuple are shifted to the right one
The Arduino is programed in C and there is no such thing as a tuple in C. That is a data construct used in Python.

What you have here is a class method called 'Color' and you are passing to it three numbers.

As to why you are having problems is anyone's guess because you have not posted all your code like it says in the How to use this forum thread that you should have read.

cwduffy01

I didn't think that the entire code was necessary, but if you would like to see it then here:

Code: [Select]

// Adafruit_NeoMatrix example for single NeoPixel Shield.
 
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#ifndef PSTR
#define PSTR // Make Arduino Due happy
#endif
 
#define PIN 3

Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(16, 16, PIN,
  NEO_MATRIX_TOP     + NEO_MATRIX_RIGHT +
  NEO_MATRIX_COLUMNS + NEO_MATRIX_PROGRESSIVE,
  NEO_GRB            + NEO_KHZ800);

uint32_t color=matrix.Color(255, 255, 255);
 
void setup()
{
  matrix.begin();
  matrix.setBrightness(5);
}

void loop()
{
  matrix.setPixelColor(0, color);
  matrix.show();
  delay(100);
}

Grumpy_Mike

Quote
I didn't think that the entire code was necessary
Yes it is important we see it all. In your case it was the libraries you used and the way you declared the instance of the libraries.

Anyway I have managed to work out what is happening. It will perform as you said, not showing the correct colours. However this is because you are using the setPixelColor method, I think that this has been designed for a simple strip.

So I looked at the header file for the NeoMatrix library and saw what functions were defined. It looks like the method you actually want to use is the drawPixel method.

This takes 5 parameters x position, y position and then a red, green and blue colour bytes or 3 parameters x position, y position and then a single colour number. Here is your code that does show the right colours. Note I changed this to just a 3 by 3 matrix because that is what I had on hand.

Code: [Select]


// Adafruit_NeoMatrix example for single NeoPixel Shield.
 
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#ifndef PSTR
#define PSTR // Make Arduino Due happy
#endif
 
#define PIN 3

Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(3, 3, PIN,
  NEO_MATRIX_TOP     + NEO_MATRIX_RIGHT +
  NEO_MATRIX_COLUMNS + NEO_MATRIX_PROGRESSIVE,
  NEO_GRB            + NEO_KHZ800);

void setup()
{
  matrix.begin();
  matrix.setBrightness(40);
  matrix.fillScreen(0);
}

uint32_t colorB =matrix.Color(0, 0, 255);
uint32_t colorG =matrix.Color(0, 255, 00);
uint32_t colorR =matrix.Color(255,0 ,0);
void loop()
{  matrix.setCursor(0, 0);
  matrix.drawPixel(0,0, colorB);
  matrix.show();
   delay(300);
  matrix.drawPixel(0,0, colorG); 
  matrix.show();
   delay(300);
  matrix.drawPixel(0,0, colorR);
  matrix.show();
   delay(300);

}
   

Go Up