Hello Everyone,
I need a help to add a ON/OFF button in my blynk project. Im trying to control my LED strips with blynk . Im trying to control the brightness with the slider, Animation with button, Color with zeRGB and i also want to add ON/OFF button. Please help me to figure it out.
Thank you in advance.
Below is my code for the project
#include <Blynk.h>
#include <FastLED.h>
#include <Adafruit_NeoPixel.h>
#define BLYNK_PRINT Serial
#include <BlynkSimpleEsp8266.h>
#define FASTLED_ESP8266_RAW_PIN_ORDER
#include "FastLED.h"
#define NUM_LEDS1 120
#define LED_TYPE WS2812
#define COLOR_ORDER GRB //CHANGED GRB TO RGB IF STILL SAME CHANGE BACK TO GRB
CRGB leds1[NUM_LEDS1];
char auth[] = "******************";
char ssid[] = "";
char pass[] = "";
#define PIN1 D2
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUM_LEDS1,PIN1, NEO_GRB + NEO_KHZ800);
int data=255;
int r,g,b;
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
pixels.begin();
FastLED.addLeds<LED_TYPE, PIN1, COLOR_ORDER>(leds1, NUM_LEDS1).setCorrection( TypicalLEDStrip );
}
void loop()
{
Blynk.run();
}
BLYNK_WRITE(V2)
{
r = param[0].asInt();
g = param[1].asInt();
b = param[2].asInt();
if(data==0)
static1(r,g,b);
}
BLYNK_WRITE(V1)
{
data = param.asInt();
static1(r, g, b,data);
}
void static1(int r, int g, int b,int brightness)
{
FastLED.setBrightness(brightness);
for (int i = 0; i < NUM_LEDS1; i++ )
{
leds1[i] = CRGB(r, g, b);
}
FastLED.show();
}
BLYNK_WRITE(V3)
{
data = param.asInt();
Serial.println(data);
if(data==0)
{
static1(r,g,b);
}
else if(data==1)
{
animation1();
}
}
void static1(int r, int g, int b)
{
for(int i=0;i<=NUM_LEDS1;i++)
{
pixels.setPixelColor(i, pixels.Color(r,g,b));
pixels.show();
}
}
void animation1()
{
for(int i=0;i<NUM_LEDS1;i++)
{
pixels.setPixelColor(i, pixels.Color(255,0,0));
pixels.show();
delay(100);
}
for(int i=NUM_LEDS1;i>=0;i--)
{
pixels.setPixelColor(i, pixels.Color(0,255,0));
pixels.show();
delay(100);
}
for(int i=0;i<NUM_LEDS1;i++)
{
pixels.setPixelColor(i, pixels.Color(0,255,255));
pixels.show();
delay(100);
}
for(int i=NUM_LEDS1;i>=0;i--)
{
pixels.setPixelColor(i, pixels.Color(255,255,0));
pixels.show();
delay(100);
}
}