Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <FastLED.h>
- FASTLED_USING_NAMESPACE
- #include <ESP8266WiFi.h>
- #include <BlynkSimpleEsp8266.h>
- // You should get Auth Token in the Blynk App.
- // Go to the Project Settings (nut icon).
- char auth[] = "3OfEectOBlaFy7KjFN885S3MeUcHHg5C";
- // Your WiFi credentials.
- // Set password to "" for open networks.
- char ssid[] = "JAN";
- char pass[] = "janusz2610567";
- bool rot = true;
- int patN=0;
- // This function will be called every time Slider Widget
- // in Blynk app writes values to the Virtual Pin 1
- BLYNK_WRITE(V1)
- {
- int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
- if (pinValue!=1) {
- rot = false;
- patN=pinValue-1;
- }
- else {
- rot = true;
- }
- // You can also use:
- // String i = param.asStr();
- // double d = param.asDouble();
- //Serial.print("V1 Slider value is: ");
- //Serial.println(pinValue);
- }
- BLYNK_WRITE(V2)
- {
- int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
- FastLED.setBrightness(pinValue);
- // You can also use:
- // String i = param.asStr();
- // double d = param.asDouble();
- //Serial.print("V1 Slider value is: ");
- //Serial.println(pinValue);
- }
- #if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001000)
- #warning "Requires FastLED 3.1 or later; check github for latest code."
- #endif
- //#define CLK_PIN 4
- #define LED_TYPE WS2811
- #define COLOR_ORDER GRB
- #define NUM_LEDS 50
- CRGB leds[2][NUM_LEDS];
- #define BRIGHTNESS 100
- #define FRAMES_PER_SECOND 60
- void setup() {
- delay(3000); // 3 second delay for recovery
- // tell FastLED about the LED strip configuration
- FastLED.addLeds<LED_TYPE, D5, COLOR_ORDER>(leds[0], NUM_LEDS).setCorrection(TypicalLEDStrip);
- FastLED.addLeds<LED_TYPE, D6, COLOR_ORDER>(leds[1], NUM_LEDS).setCorrection(TypicalLEDStrip);
- FastLED.setMaxRefreshRate( FRAMES_PER_SECOND );
- // set master brightness control
- FastLED.setBrightness(BRIGHTNESS);
- //Serial.begin(9600);
- Blynk.begin(auth, ssid, pass, IPAddress(192,168,55,106), 8080);
- }
- // List of patterns to cycle through. Each is defined as a separate function below.
- typedef void(*SimplePatternList[])(int x);
- SimplePatternList gPatterns = { confettiTwoVer, breathing, sinelon, snakeTwo, snake, rainbow, rainbowWithGlitter, confetti, 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
- uint8_t snakeN = 0;
- void loop()
- {
- if(rot){
- gPatterns[gCurrentPatternNumber](0);
- gPatterns[gCurrentPatternNumber](1);
- } else
- {
- gPatterns[patN](0);
- gPatterns[patN](1);
- }
- // 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
- EVERY_N_SECONDS(20) { nextPattern(); } // change patterns periodically
- EVERY_N_MILLISECONDS(300) { Blynk.run();}
- }
- #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
- void nextPattern()
- {
- // add one to the current pattern number, and wrap around at the end
- gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE(gPatterns);
- }
- void snake(int x) {
- snakeN = beatsin16(15, 0, NUM_LEDS-1);
- for (int i = 1; i <= snakeN; i++) {
- leds[x][i] = CHSV(gHue, 255, 255);
- }
- /*Serial.print("Pasek ");
- Serial.print(x + 1);
- Serial.print(" pos: ");
- Serial.print(snakeN);
- Serial.print("\n"); */
- }
- void snakeTwo(int x) {
- snakeN = beatsin16(15, 0, NUM_LEDS - 1);
- for (int i = 0; i <= NUM_LEDS-1; i++) {
- if (i < snakeN) {
- leds[x][i] = CHSV(gHue, 255, 255);
- }
- else {
- leds[x][i] = CRGB::Black;
- }
- }
- }
- void confettiTwoVer(int x) {
- fadeToBlackBy(leds[x], NUM_LEDS, 20);
- int pos = (beatsin16(15, 0, NUM_LEDS-1) + (random16(16)-8));
- if (pos >= NUM_LEDS-1) {
- pos = NUM_LEDS-1;
- }
- if (pos < 0) {
- pos = 0;
- }
- leds[x][pos] += CHSV(gHue + random8(64), 200, 255);
- }
- void breathing(int x) {
- for (int i = 0; i < NUM_LEDS; i++) {
- leds[x][i] = CHSV(gHue, 255, 255);
- Serial.println(i);
- }
- //fill_solid(leds[x], NUM_LEDS-1, gHue);
- fadeLightBy(leds[x], NUM_LEDS, beatsin8(15, 0, 255));
- /*Serial.print("Pasek ");
- Serial.print(x + 1);
- Serial.print(" pos: ");
- Serial.print(snakeN);
- Serial.print("\n");*/
- }
- void rainbow(int x)
- {
- // FastLED's built-in rainbow generator
- fill_rainbow(leds[x], NUM_LEDS, gHue, 7);
- }
- void rainbowWithGlitter(int x)
- {
- // built-in FastLED rainbow, plus some random sparkly glitter
- rainbow(x);
- addGlitter(80, x);
- }
- void addGlitter(fract8 chanceOfGlitter, int x)
- {
- if (random8() < chanceOfGlitter) {
- leds[x][random16(NUM_LEDS)] += CRGB::White;
- }
- }
- void confetti(int x)
- {
- // random colored speckles that blink in and fade smoothly
- fadeToBlackBy(leds[x], NUM_LEDS, 10);
- int pos = random16(NUM_LEDS);
- leds[x][pos] += CHSV(gHue + random8(64), 200, 255);
- }
- void sinelon(int x)
- {
- // a colored dot sweeping back and forth, with fading trails
- fadeToBlackBy(leds[x], NUM_LEDS, 20);
- int pos = beatsin16(7, 0, NUM_LEDS - 1);
- leds[x][pos] += CHSV(gHue, 255, 192);
- /*if (pos == 0) {
- leds[x][0] += CRGB::White;
- }*/
- }
- void bpm(int x)
- {
- // colored stripes pulsing at a defined Beats-Per-Minute (BPM)
- uint8_t BeatsPerMinute = 62;
- CRGBPalette16 palette = PartyColors_p;
- uint8_t beat = beatsin8(BeatsPerMinute, 64, 255);
- for (int i = 0; i < NUM_LEDS; i++) { //9948
- leds[x][i] = ColorFromPalette(palette, gHue + (i * 2), beat - gHue + (i * 10));
- }
- }
- void juggle(int x) {
- // eight colored dots, weaving in and out of sync with each other
- fadeToBlackBy(leds[x], NUM_LEDS, 20);
- byte dothue = 0;
- for (int i = 0; i < 8; i++) {
- leds[x][beatsin16(i + 7, 0, NUM_LEDS - 1)] |= CHSV(dothue, 200, 255);
- dothue += 32;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement