Skip to content

Instantly share code, notes, and snippets.

@achton
Last active July 8, 2021 17:24
Show Gist options
  • Save achton/e957f17bc926796626939eb59634501e to your computer and use it in GitHub Desktop.
Save achton/e957f17bc926796626939eb59634501e to your computer and use it in GitHub Desktop.
This is a quick example of a NodeMCU ESP8266 connected to a WS2812 RGB LED. It uses the Blynk.cc Android app and the corresponding Blynk Iibrary to allow the LED to be controlled via a smartphone. It also uses the FastLED library to interface with the WS2812 RGB LED. See the demo video here: https://www.youtube.com/watch?v=Bb_ayiVslMg&start=0&au…
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include "FastLED.h"
#define LED_PIN 4 // GPIO pin for RGB LEDs.
#define NUM_LEDS 1 // Number of LEDs connected.
#define BRIGHTNESS 64 // Default LED brightness.
#define LED_TYPE WS2812
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
int r = 0;
int g = 0;
int b = 0;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "blynk_auth_token_here";
void setup()
{
// power-up safety delay
delay( 3000 );
Serial.begin(9600);
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalSMD5050 );
FastLED.setBrightness( BRIGHTNESS );
Blynk.begin(auth, "ssid", "password");
}
// This assumes there is a Blynk RGB widget writing data to virtual pin V1.
BLYNK_WRITE(V1)
{
r = param[0].asInt();
g = param[1].asInt();
b = param[2].asInt();
}
void loop()
{
Blynk.run();
FastLED.clear();
leds[0] = CRGB(r, g, b);
FastLED.show();
}
@Dabandt
Copy link

Dabandt commented Jul 25, 2020

how about the WS2801 LED strips, how the #define LED_PIN works?

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment