terrag42

Vulcan Salute with Blynk (NOT working)

Feb 28th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.92 KB | None | 0 0
  1. /**************************************************************
  2.  *   Downloads, docs, tutorials: http://www.blynk.cc
  3.  *   Blynk community:            http://community.blynk.cc
  4.  *   Social networks:            http://www.fb.com/blynkapp
  5.  *                               http://twitter.com/blynk_app
  6.  * Blynk library is licensed under MIT license
  7.  */
  8. #define FASTLED_ALLOW_INTERRUPTS 0
  9. #include <FastLED.h>
  10. FASTLED_USING_NAMESPACE
  11.  
  12. extern "C" {
  13. #include "user_interface.h"
  14. }
  15. #define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
  16. #include <ESP8266WiFi.h>
  17. #include <BlynkSimpleEsp8266.h>
  18.  
  19. #if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001000)
  20. #warning "Requires FastLED 3.1 or later; check github for latest code."
  21. #endif
  22. #define LED_TYPE    WS2811
  23. #define COLOR_ORDER GRB
  24. #define NUM_LEDS    26
  25. CRGB leds[NUM_LEDS];
  26. #define BRIGHTNESS          96
  27. #define FRAMES_PER_SECOND  120
  28.  
  29. /*
  30.    1MB flash size
  31. Even though we're using a Wemos D1 Mini, use the generic ESP as board in Arduino. Flash Size: 4M (3M SPIFFS) Reset Method: nodeMCU
  32.    Blynk settings:
  33.    V0 = Toggle ON/OFF
  34.    V1 = LED pattern Menu
  35.    V2 = Infinity Depth (breathing)
  36.    V3 = Infinity Speed (breathing)
  37.    V4 palette menu
  38.    
  39.    Wemos D1 Mini connections
  40.    D3 - button
  41.    D4 - built-in led
  42.    D2 - Motor A or B conection. the other one should be grounded.
  43.  
  44. */
  45.  
  46. #define VULCAN_BUTTON   0 //D3 Same as GPIO 0
  47. #define VULCAN_LED      2 //D4 GPIO 2 Wemos D1 Mini built in LED, active LOW
  48. #define VULCAN_MOTOR    4 //D2 GPIO 4 Controlled directly by BLYNK app
  49. #define STRIP_ONE       5 //D1 GPIO 5
  50. #define STRIP_TWO       14 //D5 GPIO 14
  51. #define STRIP_THREE     12 //D6 GPIO 12
  52. #define INFINITY        13 //D7 GPIO 13 Virtual Pin V2
  53. #define SERIAL_BAUDRATE   9600
  54.  
  55. // You should get Auth Token in the Blynk App.
  56. // Go to the Project Settings (nut icon).
  57. char auth[] = "auth"; //Vulcan Salute Project
  58.  
  59. // Your WiFi credentials.
  60. // Set password to "" for open networks.
  61. char ssid[] = "ssid";
  62. char pass[] = "pass";
  63. byte breathDepth = 125;
  64. byte breathSpeed = 30;
  65. CRGBPalette16 palette = PartyColors_p; //changeable via V4 menu
  66.  
  67. void setup()
  68. {
  69.   delay(1000); // 1 second delay for recovery
  70.   //    FastLED.addLeds<LED_TYPE,STRIP_ONE,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); //STRIP_ONE is a 10 LED strip, start at index 0
  71.     FastLED.addLeds<LED_TYPE,STRIP_ONE,COLOR_ORDER>(leds, 0, 10).setCorrection(TypicalLEDStrip); //STRIP_ONE is a 10 LED strip, start at index 0
  72.     FastLED.addLeds<LED_TYPE,STRIP_TWO,COLOR_ORDER>(leds, 10, 10).setCorrection(TypicalLEDStrip); //STRIP_TWO is a 10 LED strip, start at index 10
  73.     FastLED.addLeds<LED_TYPE,STRIP_THREE,COLOR_ORDER>(leds, 20, 6).setCorrection(TypicalLEDStrip); //STRIP_THREE is a 6 LED strip, start at index 20
  74.   Serial.begin(SERIAL_BAUDRATE);
  75.   Blynk.begin(auth, ssid, pass);
  76. }
  77. // List of patterns to cycle through.  Each is defined as a separate function below.
  78. typedef void (*SimplePatternList[])();
  79. SimplePatternList gPatterns = { sinelon, juggle, bpm };
  80.  
  81. uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
  82. uint8_t gHue = 0; // rotating "base color" used by many of the patterns
  83.  
  84. BLYNK_WRITE(V1) { //LED Pattern menu
  85.   switch (param.asInt())
  86.   {
  87.     case 1: // Item 1
  88.       gCurrentPatternNumber = 0;
  89.       Serial.println("Sinelon selected");
  90.       break;
  91.     case 2: // Item 2
  92.       gCurrentPatternNumber = 1;
  93.       Serial.println("juggle selected");
  94.       break;
  95.     case 3: // Item 3
  96.       gCurrentPatternNumber = 2;
  97.       Serial.println("BPM selected");
  98.       break;
  99.     default:
  100.       Serial.println("Unknown item selected");
  101.   }
  102. }
  103.  
  104. BLYNK_WRITE(V4) { //Palette menu (currently only used in BPM pattern)
  105.   switch (param.asInt())
  106.   {
  107.     case 1: // Item 1
  108.       palette = PartyColors_p;
  109.       Serial.println("Party Colors selected");
  110.       break;
  111.     case 2: // Item 2
  112.       palette = CloudColors_p;
  113.       Serial.println("Cloud Colors selected");
  114.       break;
  115.     case 3: // Item 3
  116.       palette = LavaColors_p;
  117.       Serial.println("Lava Colors selected");
  118.       break;
  119.     default:
  120.       Serial.println("Unknown item selected");
  121.   }
  122. }
  123.  
  124. BLYNK_WRITE(V2) //Infinity Slider Widget is writing to pin V2
  125. {
  126.   breathDepth = param.asInt();
  127.   Serial.print("breathDepth set to ");
  128.   Serial.print(breathDepth);
  129. }
  130. BLYNK_WRITE(V3) //Infinity Slider Widget is writing to pin V3
  131. {
  132.   breathSpeed = param.asInt();
  133.   Serial.print("breathSpeed set to ");
  134.   Serial.print(breathSpeed);
  135. }
  136. void loop()
  137. {
  138.   Blynk.run();
  139.   // Call the current pattern function once, updating the 'leds' array
  140.   gPatterns[gCurrentPatternNumber]();
  141.  
  142.   // send the 'leds' array out to the actual LED strip
  143.   FastLED.show();  
  144.   // insert a delay to keep the framerate modest
  145.   FastLED.delay(1000/FRAMES_PER_SECOND);
  146.  
  147.   // do some periodic updates
  148.   //EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
  149.   analogWrite(INFINITY, beatsin8(breathSpeed, 0, breathDepth)); //lower slider value = less speed
  150.  }
  151.  
  152. void sinelon()
  153. {
  154.   // a colored dot sweeping back and forth, with fading trails
  155.   fadeToBlackBy( leds, NUM_LEDS, 20);
  156.   int pos = beatsin16(13,0,NUM_LEDS);
  157.   leds[pos] += CHSV( gHue, 255, 192);
  158. }
  159.  
  160. void bpm()
  161. {
  162.   // colored stripes pulsing at a defined Beats-Per-Minute (BPM)
  163.   //uint8_t BeatsPerMinute = 62; //Select via breathSpeed (V
  164.   //CRGBPalette16 palette = PartyColors_p; //select via V4 menu!
  165.   //uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
  166.   uint8_t beat = beatsin8( breathSpeed, 64, 255);
  167.   for( int i = 0; i < NUM_LEDS; i++) { //9948
  168.     leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
  169.   }
  170. }
  171.  
  172. void juggle() {
  173.   // eight colored dots, weaving in and out of sync with each other
  174.   fadeToBlackBy( leds, NUM_LEDS, 20);
  175.   byte dothue = 0;
  176.   for( int i = 0; i < 8; i++) {
  177.     leds[beatsin16(i+7,0,NUM_LEDS)] |= CHSV(dothue, 200, 255);
  178.     dothue += 32;
  179.   }
  180. }
Advertisement
Add Comment
Please, Sign In to add comment