I created a wrapping class in C++ for Adafruit Neopixel (I used it in my personal project). The question is... is it possible to represent more than 7 colors?. Is this a Neopixel limitation or hardware limitation (the on-board RGB led uses only 1 gpio). Sending differente brigthness level to R,G,B does not work.
That's my test code. It works like a charm. Even with 7 colors (+black) is enough for my project, but I'm curious about that:
#include <Arduino.h>
#include "rgbonbard.hpp"
RgbOnboard rgb;
void setup() {
// BY DEFAULT THE GPIO IS RGB_BUILTIN, but you can change it with...
// POR DEFECTO EL GPIO ES RGB_BUILTIN, pero puedes cambiarlo con...
// rgb.setGpio(your_gio_number);
rgb.setBrightness(0.15f); // from 0.0 to 1.0 (0% - 100%)
}
void loop() {
// Test all available colors
// Testear todos los colores disponibles
for (auto color : {
color::red, color::green, color::blue, color::cyan, color::purple,
color::yellow, color::white, color::black}) {
rgb.setColor(color);
delay(2000);
}
}
Of course it is. Each LED can have one of 256 colours so the combined possible number of colours is 256 * 256 * 256, ie 16,777,216 different colours, not that the human eye can distinguish that many
Yes, I know how to create a RGB color, but this is no my question.
Using I.E dodger blue: neopixelWrite(gpio_num, 0X1E, 0x90, 0xFF) in the on-board RGB Led does not work. With neopixel the color only woks sending the same value of brightness:
Doesnt matter, it's only a wrap class. Using directly neopixelWrite() same result. This is the sample code of arduino IDE. As you can see, it sets the same brightness level.
Official example of Arduino IDE. Examples/ESP32/GPIO/RGBBlink.
/*
BlinkRGB
Demonstrates usage of onboard RGB LED on some ESP dev boards.
Calling digitalWrite(RGB_BUILTIN, HIGH) will use hidden RGB driver.
RGBLedWrite demonstrates controll of each channel:
void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val)
WARNING: After using digitalWrite to drive RGB LED it will be impossible to drive the same pin
with normal HIGH/LOW level
*/
//#define RGB_BRIGHTNESS 64 // Change white brightness (max 255)
// the setup function runs once when you press reset or power the board
void setup() {
// No need to initialize the RGB LED
}
// the loop function runs over and over again forever
void loop() {
#ifdef RGB_BUILTIN
digitalWrite(RGB_BUILTIN, HIGH); // Turn the RGB LED white
delay(1000);
digitalWrite(RGB_BUILTIN, LOW); // Turn the RGB LED off
delay(1000);
neopixelWrite(RGB_BUILTIN,RGB_BRIGHTNESS,0,0); // Red
delay(1000);
neopixelWrite(RGB_BUILTIN,0,RGB_BRIGHTNESS,0); // Green
delay(1000);
neopixelWrite(RGB_BUILTIN,0,0,RGB_BRIGHTNESS); // Blue
delay(1000);
neopixelWrite(RGB_BUILTIN,0,0,0); // Off / black
delay(1000);
#endif
}
This function prototype seems to indicate that the full range of colours is available. What happens if you use a value other than RGB_BRIGHTNESS in the function ?
// Colors from https://www.rapidtables.com/web/color/RGB_Color.html
neopixelWrite(RGB_BUILTIN,75,0,130); // Indigo ==> Display white
delay(1000);
neopixelWrite(RGB_BUILTIN,50,205,50); // Lime green ==> Display white
delay(1000);
neopixelWrite(RGB_BUILTIN,139,69,19); // Saddle brown ==> Display white
delay(1000);
The ESP32 features an RGB LED that can be controlled with the
LED_RED, LED_GREEN and LED_BLUE pin names. These pins are not accessible on the headers of the board, and can only be used for the RGB LED.
Some boards from the first limited production batch were assembled with a different RGB LED which has the green and blue pins inverted. Read our full Help Center article here
As was pointed out, you don't have a neopixel (w/programmable driver) but an RGB led.
If your code does not block execution (no delays!) then one function in loop() can blink the 3 colors using soft-PWM. With the ESP clock rate, how many shades do you want?
Out of interest the Nano ESP32 RGB is a 3 color common anode led with R = D14 G = D15 B = D16 ( GPIO46 GPIO0 GPIO45 micropython) and you can get different colors adjusting the duty values of PWM
P.S. as it says the pins are not available for use externally