Last active
July 8, 2021 17:24
-
-
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…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how about the WS2801 LED strips, how the #define LED_PIN works?
thanks