1 (edited by Kickster 2019-04-19 16:40:10)

Topic: How work with RGB Color?

Hi, as a Arduino newbie I have a question. I want remote my WS2811 adressable led strip through RGB color panel. Best choice for me are three variables - red, green, blue - and work with them, but i dunno how to earn them. There is my in-progress sketch:

//////////////////////////////////////////////
//        RemoteXY include library          //
//////////////////////////////////////////////

// RemoteXY select connection mode and include library 
#define REMOTEXY_MODE__ESP8266WIFI_LIB_POINT
#include <ESP8266WiFi.h>
#include <RemoteXY.h>


// RemoteXY connection settings 
#define REMOTEXY_WIFI_SSID "RemoteXY"
#define REMOTEXY_WIFI_PASSWORD "12345678"
#define REMOTEXY_SERVER_PORT 6377


// RemoteXY configurate   
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
  { 255,3,0,0,0,11,0,8,24,0,
  6,0,20,4,55,55,24,24 };
   
// this structure defines all the variables of your control interface 
struct {

    // input variable
  uint8_t LOOL_r; // =0..255 Red color value
  uint8_t LOOL_g; // =0..255 Green color value
  uint8_t LOOL_b; // =0..255 Blue color value

    // other variable
  uint8_t connect_flag;  // =1 if wire connected, else =0

} RemoteXY;
#pragma pack(pop)

/////////////////////////////////////////////
//           END RemoteXY include          //
/////////////////////////////////////////////
#include <Adafruit_NeoPixel.h>


#define PIN            14
#define NUMPIXELS      100
#define LED_COUNT      60

Adafruit_NeoPixel strip(LED_COUNT, PIN, NEO_GRB + NEO_KHZ400);


void setup() 
{
  RemoteXY_Init ();
  strip.begin();           // INITIALIZE NeoPixel strip object (REQUIRED)
  strip.show();            // Turn OFF all pixels ASAP
  strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)   
   
   
  // TODO you setup code
   
}

void loop()  {
  RemoteXY_Handler ();
  colorWipe( strip.Color( RemoteXY.LOOL_r,   RemoteXY.LOOL_g,  RemoteXY.LOOL_b ));
 
}   
  // TODO you loop code
  // use the RemoteXY structure for data transfer

void colorWipe(uint8_t color) {
  for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
    strip.setPixelColor(i, color);         //  Set pixel's color (in RAM)
    strip.show();                          //  Update strip to match
  }
}

Thank you for all advices smile

2 (edited by Guillaume 2019-04-19 12:23:32)

Re: How work with RGB Color?

Welcome

This doesn't work ?

colorWipe( strip.Color( RemoteXY.LOOL_r,   RemoteXY.LOOL_g,  RemoteXY.LOOL_b ), 50 );

3

Re: How work with RGB Color?

Yeah, it works in program, but in app is unlimited connecting loading, and then... "Socket create error: Host unreachable". But without colorWipe it works fine, sadly but not for me sad

4

Re: How work with RGB Color?

First, place strip.show(); after the for loop. You want to update once, not every loop iteration. Second, you have a "wait" parameter in the colorWipe function. What is it? Some delay() that you removed? You cannot have blocking code.

5 (edited by Kickster 2019-04-19 16:40:58)

Re: How work with RGB Color?

int wait was only some thing I coppied from another code. Removed. For the strip.show() - I need change the colors in real time (sure +- few millisecs) so I need the update every loop... Hope I´m right big_smile

I edited code up.

6 (edited by Guillaume 2019-04-19 16:48:16)

Re: How work with RGB Color?

What about you call colorWipe only when the color values changed ?

void loop()
{
    RemoteXY_Handler();
    
    static uint8_t prevR = RemoteXY.LOOL_r;
    static uint8_t prevG = RemoteXY.LOOL_g;
    static uint8_t prevB = RemoteXY.LOOL_b;
    
    if ( RemoteXY.LOOL_r != prevR || RemoteXY.LOOL_g != prevG || RemoteXY.LOOL_b != prevB )
    {
        prevR = RemoteXY.LOOL_r;
        prevG = RemoteXY.LOOL_g;
        prevB = RemoteXY.LOOL_b;
        colorWipe( strip.Color( RemoteXY.LOOL_r,   RemoteXY.LOOL_g,  RemoteXY.LOOL_b ));
    }
}

7

Re: How work with RGB Color?

IT WORKS! Only for blue color, but I´ll try some repair magic. Thank you!

8

Re: How work with RGB Color?

Nice wink

9

Re: How work with RGB Color?

Okay... my last wish I hope big_smile Don´t see any reason why is working only blue color:


//////////////////////////////////////////////
//        RemoteXY include library          //
//////////////////////////////////////////////

// RemoteXY select connection mode and include library 
#define REMOTEXY_MODE__ESP8266WIFI_LIB_POINT
#include <ESP8266WiFi.h>
#include <RemoteXY.h>


// RemoteXY connection settings 
#define REMOTEXY_WIFI_SSID "RemoteXY"
#define REMOTEXY_WIFI_PASSWORD "12345678"
#define REMOTEXY_SERVER_PORT 6377


// RemoteXY configurate   
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
  { 255,3,0,0,0,11,0,8,24,0,
  6,0,20,4,55,55,24,24 };
   
// this structure defines all the variables of your control interface 
struct {

    // input variable
  uint8_t LOOL_r; // =0..255 Red color value
  uint8_t LOOL_g; // =0..255 Green color value
  uint8_t LOOL_b; // =0..255 Blue color value

    // other variable
  uint8_t connect_flag;  // =1 if wire connected, else =0

} RemoteXY;
#pragma pack(pop)

/////////////////////////////////////////////
//           END RemoteXY include          //
/////////////////////////////////////////////
#include <Adafruit_NeoPixel.h>


#define PIN            14
#define NUMPIXELS      100
#define LED_COUNT      60

Adafruit_NeoPixel strip(LED_COUNT, PIN, NEO_GRB + NEO_KHZ400);


void setup() 
{
  RemoteXY_Init ();
  strip.begin();           // INITIALIZE NeoPixel strip object (REQUIRED)
  strip.show();            // Turn OFF all pixels ASAP
  strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)   
   
   
  // TODO you setup code
   
}

void loop()  {
  {
    RemoteXY_Handler();
   
    static uint8_t prevR = RemoteXY.LOOL_r;
    static uint8_t prevG = RemoteXY.LOOL_g;
    static uint8_t prevB = RemoteXY.LOOL_b;
   
    if ( RemoteXY.LOOL_r != prevR || RemoteXY.LOOL_g != prevG || RemoteXY.LOOL_b != prevB )
    {
        prevR = RemoteXY.LOOL_r;
        prevG = RemoteXY.LOOL_g;
        prevB = RemoteXY.LOOL_b;
        colorWipe( strip.Color( RemoteXY.LOOL_r,   RemoteXY.LOOL_g,  RemoteXY.LOOL_b ));
    }
}
}
  // TODO you loop code
  // use the RemoteXY structure for data transfer

void colorWipe(uint8_t color) {
  for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
    strip.setPixelColor(i, color);         //  Set pixel's color (in RAM)
    strip.show();                          //  Update strip to match
  }
}

If anybody know, I´ll be very glad, thanks smile

10

Re: How work with RGB Color?

Change

void colorWipe(uint8_t color) {

To

void colorWipe(uint32_t color) {

Then it should work..

11

Re: How work with RGB Color?

Magnificent! Thanks!