Advertisement
Guest User

ESP8266 + Blynk + Adafruit DotStar library

a guest
Jul 25th, 2015
1,252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.54 KB | None | 0 0
  1. #include <Adafruit_DotStar.h>
  2. #include <SPI.h>
  3. #include <ESP8266WiFi.h>
  4. #include <BlynkSimpleEsp8266.h>
  5.  
  6. #define NUMPIXELS 60
  7.  
  8. #define DATAPIN    15 // GPIO15 - MISO
  9. #define CLOCKPIN  14 // GPIO14 - CLK
  10.  
  11. Adafruit_DotStar strip = Adafruit_DotStar(NUMPIXELS, DATAPIN, CLOCKPIN);
  12. char auth[] = "629c4b81452040xxxxxxxxxxxxxxxxxx";
  13.  
  14. void setup() {
  15.   Blynk.begin(auth, "YOUR SSID", "YOUR PASS");
  16.   strip.begin();
  17.   strip.show();
  18. }
  19.  
  20. int      head  = 0, tail = -10, color_r=255, color_g=0, color_b=0; //initially set to show red only
  21. uint32_t color = 0xFF0000;
  22. uint8_t count=0;
  23. BLYNK_WRITE(1) { //in blynk app, large RED slider set to virtual pin 1 with minimum = 0 and maximum = 255
  24.      color_r = param.asInt();
  25. }
  26. BLYNK_WRITE(2) { //in blynk app, large GREEN slider set to virtual pin 2 with minimum = 0 and maximum = 255
  27.      color_g = param.asInt();
  28. }
  29. BLYNK_WRITE(3) { //in blynk app, large BLUE slider set to virtual pin 3 with minimum = 0 and maximum = 255
  30.      color_b = param.asInt();
  31. }
  32. uint32_t ticker=millis();
  33. void loop() {
  34.   Blynk.run(); // Initiates Blynk
  35.   strip.setPixelColor(head, color);
  36.   strip.setPixelColor(tail, 0);
  37.   strip.show();
  38. if (millis()-ticker>20) {//this substitutes for the 20 millisecond delay
  39. ticker= millis();
  40. //  delay(20);
  41. color <<= 8; //shift 8 bits to the left to clear out previous value
  42. color |= color_r;
  43. color <<=8;
  44. color |= color_g;
  45. color <<=8;
  46. color |= color_b;
  47.   if(++head >= NUMPIXELS) {
  48.     count++;
  49.     head = 0;
  50.     //if((color >>= 8) == 0)  
  51.   }
  52.   if(++tail >= NUMPIXELS) tail = 0;
  53.  }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement