Skip to content

Instantly share code, notes, and snippets.

@tairea
Last active September 21, 2021 09:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tairea/d42e825f59d4d97a3e058a70d80d5a4e to your computer and use it in GitHub Desktop.
Save tairea/d42e825f59d4d97a3e058a70d80d5a4e to your computer and use it in GitHub Desktop.
Arduino: Blynk Led Strip (NodeMCU + Led Strip - colour & brightness)
#define BLYNK_TEMPLATE_ID "blynk_template_id"
#define BLYNK_DEVICE_NAME "Quickstart Device"
#define BLYNK_AUTH_TOKEN "blynk_auth_token"
// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// FastLED stuff
#define FASTLED_ESP8266_RAW_PIN_ORDER
#include "FastLED.h"
#define NUM_LEDS1 21
#define LED_TYPE WS2811
#define COLOR_ORDER GRB
CRGB leds1[NUM_LEDS1];
#define PIN1 D4
int data=255;
int r,g,b;
char auth[] = BLYNK_AUTH_TOKEN;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "wifi_name";
char pass[] = "wifi_pass";
// choose colour - using Blynk zeRGBa widget
BLYNK_WRITE(V1)
{
// get rgb values from V1 params (in Blynk Datastreams V1 pin needs to be type 'string')
r = param[0].asInt();
g = param[1].asInt();
b = param[2].asInt();
// print values to serial
Serial.print("r");
Serial.println(r);
Serial.print("g");
Serial.println(g);
Serial.print("b");
Serial.println(b);
static1(r, g, b,data);
}
// choose brightness - using Blynk slider widget
BLYNK_WRITE(V2)
{
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();
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
FastLED.addLeds<LED_TYPE, PIN1, COLOR_ORDER>(leds1, NUM_LEDS1).setCorrection( TypicalLEDStrip );
}
void loop()
{
Blynk.run();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment