Hi!
I’m currently building a sunrise simulator lamp for my 3yo son.
Read a lot of documentation, proceeded to many tests using esp8266 nodemcu 12E, worked fine using ZeRGBa and some virtual buttons to light a led strip in the colors I wanted, so as for different sliders.(still during tests).
I managed to write a sunrise code for the WS2811 RGB led strip (sorry if it’s not perfect, i’m quite new in coding), put it in a new project using the same auth,SSID and Wifi password.
Got the nodemcu connected, had the virtual button set up, nodemcu connected.
When I use it to begin, the sunrise starts and after 15-20 seconds a notification appears " test" (name of the project on blynk app) is offline.
I deleted all the code and set a virtual button to light the ledstrip in one color-> no deconection, same for ZeRGBa.
I assume it’s the whole code which is maybe too heavy for the nodemcu to manage it.
Thanks for your help.
50 ws2811 leds on the thed strip.
5V 8A power supply.
Esp8266 wired on the power supply using a nano usb port.
Led Strip wired also to the power supply (shared +5v and gnd for esp and led strip)
Data ledstrip connected on D4.
#include <FastLED.h>
#define LED_PIN 4 //CONFIGURE LED STRIP HERE
#define NUM_LEDS 50
#define BRIGHTNESS 255
#define LED_TYPE WS2811
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
#define UPDATES_PER_SECOND 100
#define BLYNK_PRINT Serial
#include <BlynkSimpleEsp8266.h>
#define FASTLED_ESP8266_RAW_PIN_ORDER
#include <SPI.h>
char auth[] = "-----";
char ssid[] = "----";
char pass[] = "----";
int data=255;
int r,g,b;
//Previous value of RGB
int redPrevious, greenPrevious, bluePrevious = 0;
//Current value of RGB
float redCurrent, greenCurrent, blueCurrent = 0;
//Target value of RGB
int redTarget, greenTarget, blueTarget = 0;
int fade_delay = 100;
int steps = 200;
void setup() {
Serial.begin(9600);
delay( 3000 ); // power-up safety delay
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
Blynk.begin(auth, ssid, pass);
}
BLYNK_WRITE(V2)
{
int R = param[0].asInt();
int G = param[1].asInt();
int B = param[2].asInt();
Serial.println(R);
Serial.println(G);
Serial.println(B);
for(int i=0;i<NUM_LEDS;i++){
FadeToColour(0, 0, 100);
FadeToColour(0, 100, 100);
FadeToColour(0, 100, 0);
FadeToColour(0, 150, 0);
FadeToColour(50, 150, 0);
FadeToColour(100, 200, 0);
FadeToColour(160, 200, 0);
FadeToColour(200, 255, 0);
FadeToColour(255, 255, 0);
FadeToColour(255, 255, 255);
}
}
void FadeToColour(int r, int g, int b) {
redPrevious = redCurrent;
greenPrevious = greenCurrent;
bluePrevious = blueCurrent;
redTarget = r;
greenTarget = g;
blueTarget = b;
float redDelta = redTarget - redPrevious;
redDelta = redDelta / steps;
float greenDelta = greenTarget - greenPrevious;
greenDelta = greenDelta / steps;
float blueDelta = blueTarget - bluePrevious;
blueDelta = blueDelta / steps;
for (int j = 1; j < steps; j++) {
redCurrent = redPrevious + (redDelta * j);
greenCurrent = greenPrevious + (greenDelta * j);
blueCurrent = bluePrevious + (blueDelta * j);
setColour(redCurrent, greenCurrent, blueCurrent, 6);
delay(fade_delay); //Delay between steps
}
delay(1000); //Wait at peak colour before continuing
}
void setColour(int r, int g, int b, int lednum) {
Serial.println(r);
for(int i=0; i<NUM_LEDS;i++){
leds[i] = CRGB(r, g, b);
FastLED.show();
}
}
void loop()
{
Blynk.run();
}