Advertisement
KenFalco

WS2812(B)-ESP8266

Apr 25th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. // ESP-8266
  2. //Led Strip WS2812(B)
  3.  
  4. /*
  5. RED        -> V0    Send on release (ON) 0 -> 255
  6. GREEN      -> V1    Send on release (ON) 0 -> 255
  7. BLUE       -> V2    Send on release (ON) 0 -> 255
  8. BRIGHTNESS -> V3    Send on release (ON) 0 -> 255
  9. */
  10.  
  11. #include <BlynkSimpleEsp8266.h>
  12. #include <ESP8266WiFi.h>
  13. #include <Adafruit_NeoPixel.h>
  14.  
  15. #define LEDS 64
  16. #define STRIP_PIN 2
  17.  
  18. char auth[] = "Codice";
  19. char ssid[] = "Uaifai";
  20. char pass[] = "Password";
  21.  
  22. Adafruit_NeoPixel pixels = Adafruit_NeoPixel(LEDS, STRIP_PIN, NEO_GRB + NEO_KHZ800); //N° Leds e N° pin
  23.  
  24. volatile uint8_t red = 0, green = 0, blue = 0, brightness = 0;
  25.  
  26. void showUpdates() {
  27.   //Show updates of all leds
  28.   pixels.clear();
  29.   for (uint16_t px = 0; px < LEDS; ++px) {
  30.     pixels.setPixelColor(px, red, blue, green, brightness);
  31.   }
  32.   pixels.show();
  33. }
  34.  
  35. BLYNK_WRITE(V0) {
  36.   //RED
  37.   red = param.asInt();
  38.   showUpdates();
  39. }
  40.  
  41. BLYNK_WRITE(V1) {
  42.   //GREEN
  43.   green = param.asInt();
  44.   showUpdates();
  45. }
  46.  
  47. BLYNK_WRITE(V2) {
  48.   //BLUE
  49.   blue = param.asInt();
  50.   showUpdates();
  51. }
  52.  
  53. BLYNK_WRITE(V3) {
  54.   //BRIGHTNESS
  55.   brightness = param.asInt();
  56.   showUpdates();
  57. }
  58.  
  59. void setup() {
  60.   pixels.begin(); //INIT strip
  61.   pixels.clear(); //All leds 'off'
  62.   Blynk.begin(auth, ssid, pass);
  63. }
  64.  
  65. void loop() {
  66.   Blynk.run();
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement