Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**************************************************************
- * Downloads, docs, tutorials: http://www.blynk.cc
- * Blynk community: http://community.blynk.cc
- * Social networks: http://www.fb.com/blynkapp
- * http://twitter.com/blynk_app
- * Blynk library is licensed under MIT license
- */
- #define FASTLED_ALLOW_INTERRUPTS 0
- #include <FastLED.h>
- FASTLED_USING_NAMESPACE
- extern "C" {
- #include "user_interface.h"
- }
- #define BLYNK_PRINT Serial // Comment this out to disable prints and save space
- #include <ESP8266WiFi.h>
- #include <BlynkSimpleEsp8266.h>
- #if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001000)
- #warning "Requires FastLED 3.1 or later; check github for latest code."
- #endif
- #define LED_TYPE WS2811
- #define COLOR_ORDER GRB
- #define NUM_LEDS 26
- CRGB leds[NUM_LEDS];
- #define BRIGHTNESS 96
- #define FRAMES_PER_SECOND 120
- /*
- 1MB flash size
- 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
- Blynk settings:
- V0 = Toggle ON/OFF
- V1 = LED pattern Menu
- V2 = Infinity Depth (breathing)
- V3 = Infinity Speed (breathing)
- V4 palette menu
- Wemos D1 Mini connections
- D3 - button
- D4 - built-in led
- D2 - Motor A or B conection. the other one should be grounded.
- */
- #define VULCAN_BUTTON 0 //D3 Same as GPIO 0
- #define VULCAN_LED 2 //D4 GPIO 2 Wemos D1 Mini built in LED, active LOW
- #define VULCAN_MOTOR 4 //D2 GPIO 4 Controlled directly by BLYNK app
- #define STRIP_ONE 5 //D1 GPIO 5
- #define STRIP_TWO 14 //D5 GPIO 14
- #define STRIP_THREE 12 //D6 GPIO 12
- #define INFINITY 13 //D7 GPIO 13 Virtual Pin V2
- #define SERIAL_BAUDRATE 9600
- // You should get Auth Token in the Blynk App.
- // Go to the Project Settings (nut icon).
- char auth[] = "auth"; //Vulcan Salute Project
- // Your WiFi credentials.
- // Set password to "" for open networks.
- char ssid[] = "ssid";
- char pass[] = "pass";
- byte breathDepth = 125;
- byte breathSpeed = 30;
- CRGBPalette16 palette = PartyColors_p; //changeable via V4 menu
- void setup()
- {
- delay(1000); // 1 second delay for recovery
- // FastLED.addLeds<LED_TYPE,STRIP_ONE,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); //STRIP_ONE is a 10 LED strip, start at index 0
- FastLED.addLeds<LED_TYPE,STRIP_ONE,COLOR_ORDER>(leds, 0, 10).setCorrection(TypicalLEDStrip); //STRIP_ONE is a 10 LED strip, start at index 0
- FastLED.addLeds<LED_TYPE,STRIP_TWO,COLOR_ORDER>(leds, 10, 10).setCorrection(TypicalLEDStrip); //STRIP_TWO is a 10 LED strip, start at index 10
- FastLED.addLeds<LED_TYPE,STRIP_THREE,COLOR_ORDER>(leds, 20, 6).setCorrection(TypicalLEDStrip); //STRIP_THREE is a 6 LED strip, start at index 20
- Serial.begin(SERIAL_BAUDRATE);
- Blynk.begin(auth, ssid, pass);
- }
- // List of patterns to cycle through. Each is defined as a separate function below.
- typedef void (*SimplePatternList[])();
- SimplePatternList gPatterns = { sinelon, juggle, bpm };
- uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
- uint8_t gHue = 0; // rotating "base color" used by many of the patterns
- BLYNK_WRITE(V1) { //LED Pattern menu
- switch (param.asInt())
- {
- case 1: // Item 1
- gCurrentPatternNumber = 0;
- Serial.println("Sinelon selected");
- break;
- case 2: // Item 2
- gCurrentPatternNumber = 1;
- Serial.println("juggle selected");
- break;
- case 3: // Item 3
- gCurrentPatternNumber = 2;
- Serial.println("BPM selected");
- break;
- default:
- Serial.println("Unknown item selected");
- }
- }
- BLYNK_WRITE(V4) { //Palette menu (currently only used in BPM pattern)
- switch (param.asInt())
- {
- case 1: // Item 1
- palette = PartyColors_p;
- Serial.println("Party Colors selected");
- break;
- case 2: // Item 2
- palette = CloudColors_p;
- Serial.println("Cloud Colors selected");
- break;
- case 3: // Item 3
- palette = LavaColors_p;
- Serial.println("Lava Colors selected");
- break;
- default:
- Serial.println("Unknown item selected");
- }
- }
- BLYNK_WRITE(V2) //Infinity Slider Widget is writing to pin V2
- {
- breathDepth = param.asInt();
- Serial.print("breathDepth set to ");
- Serial.print(breathDepth);
- }
- BLYNK_WRITE(V3) //Infinity Slider Widget is writing to pin V3
- {
- breathSpeed = param.asInt();
- Serial.print("breathSpeed set to ");
- Serial.print(breathSpeed);
- }
- void loop()
- {
- Blynk.run();
- // Call the current pattern function once, updating the 'leds' array
- gPatterns[gCurrentPatternNumber]();
- // send the 'leds' array out to the actual LED strip
- FastLED.show();
- // insert a delay to keep the framerate modest
- FastLED.delay(1000/FRAMES_PER_SECOND);
- // do some periodic updates
- //EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
- analogWrite(INFINITY, beatsin8(breathSpeed, 0, breathDepth)); //lower slider value = less speed
- }
- void sinelon()
- {
- // a colored dot sweeping back and forth, with fading trails
- fadeToBlackBy( leds, NUM_LEDS, 20);
- int pos = beatsin16(13,0,NUM_LEDS);
- leds[pos] += CHSV( gHue, 255, 192);
- }
- void bpm()
- {
- // colored stripes pulsing at a defined Beats-Per-Minute (BPM)
- //uint8_t BeatsPerMinute = 62; //Select via breathSpeed (V
- //CRGBPalette16 palette = PartyColors_p; //select via V4 menu!
- //uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
- uint8_t beat = beatsin8( breathSpeed, 64, 255);
- for( int i = 0; i < NUM_LEDS; i++) { //9948
- leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
- }
- }
- void juggle() {
- // eight colored dots, weaving in and out of sync with each other
- fadeToBlackBy( leds, NUM_LEDS, 20);
- byte dothue = 0;
- for( int i = 0; i < 8; i++) {
- leds[beatsin16(i+7,0,NUM_LEDS)] |= CHSV(dothue, 200, 255);
- dothue += 32;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment