Go Down

Topic: RGB NeoPixel ESP8266 Help!( (Read 445 times) previous topic - next topic


There is Homeridge sketch. I want to add to it the "smoothness of switching" colors. Now, when the color / percent of the glow changes, it all somehow jerks (not smooth).
It seems like it can be implemented via FadeSpeed, I don't know exactly..
Help  :smiley-roll-sweat:
Code: [Select]

#include <ESP8266WiFi.h>
#include <Adafruit_NeoPixel.h>
#include <math.h>

// Which pin On which pin is the ESP8266-12E connected to the NeoPixels
#define PIN 4

// How many NeoPixels are attached to the ESP8266-12E
#define NUMPIXELS      8
// 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(8, PIN, NEO_GRB + NEO_KHZ800);


WiFiServer server(80); //Set server port

String readString;           //String to hold incoming request
String hexString = "000000"; //Define inititial color here (hex value)

int state;

int r;
int g;
int b;

float R;
float G;
float B;

int x;
int V;

const char* ssid = "***";
const char* password = "***";
IPAddress ip(192,168,1,110);      // set a fixed IP for the NodeMCU
IPAddress gateway(192,168,1,1);  // Your router IP
IPAddress subnet(255,255,255,0); // Subnet mask

void WiFiStart() {
  Serial.print("Connecting to ");
  WiFi.begin(ssid, password);
  WiFi.config(ip, gateway, subnet);
  while (WiFi.status() != WL_CONNECTED) {
  Serial.print("IP address: ");


void allOff() {
  for(int i=0;i<8;i++)
  strip.setPixelColor(i, 0, 0, 0);

//Write requested hex-color to the pins
void setHex() {
  state = 1;
  long number = (long) strtol( &hexString[0], NULL, 16);
  r = number >> 16;
  g = number >> 8 & 0xFF;
  b = number & 0xFF;

  for(int i=0;i<8;i++)
  strip.setPixelColor (i, r, g, b);

//Compute current brightness value
void getV() {
  R = roundf(r/2.55);
  G = roundf(g/2.55);
  B = roundf(b/2.55);
  x = _max(R,G);
  V = _max(x, B);

//For serial debugging only
void showValues() {
  Serial.print("Status on/off: ");
  Serial.print("RGB color: ");
  Serial.print("Hex color: ");
  Serial.print("Brightness: ");

void setup(){
  setHex(); //Set initial color after booting. Value defined above
  showValues(); //Uncomment for serial output

  strip.show(); // Initialize all pixels to 'off'

void loop() {
  //Reconnect on lost WiFi connection
  if (WiFi.status() != WL_CONNECTED) {
  WiFiClient client = server.available();
  if (!client) {
  while(client.connected() && !client.available()) {
  //Respond on certain Homebridge HTTP requests
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        if (readString.length() < 100) {
          readString += c;
        if (c == '\n') {
          Serial.print("Request: "); //Uncomment for serial output
          Serial.println(readString); //Uncomment for serial output
          //Send reponse
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          if(readString.indexOf("on") >0) {
          if(readString.indexOf("off") >0) {

          //Set color
          if(readString.indexOf("set") >0) {
            hexString = "";
            hexString = (readString.substring(9,15));
          //Status on/off
          if(readString.indexOf("status") >0) {

          //Status color (hex)
          if(readString.indexOf("color") >0) {

          //Status brightness (%)
          if(readString.indexOf("bright") >0) {


Code: [Select]
#define NUMPIXELS      8
Adafruit_NeoPixel strip = Adafruit_NeoPixel(8, PIN, NEO_GRB + NEO_KHZ800);
  for(int i=0;i<8;i++)
  for(int i=0;i<8;i++)

What was the point of giving 8 a nice name when you never use the name?

Now, when the color / percent of the glow changes
What causes the color / brightness to change? The only thing that I can see that causes a change is input from a web client.

it all somehow jerks (not smooth).
Pretend that we can not see what is happening. Because we can't. You need to do a MUCH better job of describing the problem.

It seems like it can be implemented via FadeSpeed
What can? There is nothing in your code remotely like FadeSpeed, so this statement seems unlikely.

Code: [Select]
        if (readString.length() < 100) {
          readString += c;

Since you KNOW the maximum number of characters that you will deal with, there is NO point in pissing away resources using the String class to hold a known amount of data.

The art of getting good answers lies in asking good questions.

Go Up