Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <SoftwareSerial.h>
- SoftwareSerial DebugSerial(2, 3); // RX, TX
- #define BLYNK_PRINT DebugSerial
- #include <BlynkSimpleStream.h>
- #define BLYNK_PRINT
- #define BLYNK_PRINT Serial
- #include <FastLED.h>
- #define BLYNK_MSG_LIMIT 200
- #define DATA_PIN 6
- char auth[] = "ea8d214b9f2148d78a3e6152ba9d80a8";
- #define NUM_LEDS 40
- int HardwareZone = 3;
- int varHue;
- int varHuePrev;
- int varHueNew;
- int varSaturation;
- int varBrightness;
- int varManualMode;
- int varNextColour;
- int varNextColourPrev;
- int varBlendingMode;
- int varUpdatesPerSec;
- int varAlertMode;
- int varZone;
- CRGB leds[NUM_LEDS];
- //////////////////////////////////////////////////////////////////////////////////////////
- void setup()
- {
- varHue = 190; // Start on a Blue Hue
- varSaturation = 255; // Start Full Colour
- varBrightness = 255; // Start Full Brightness
- varManualMode = 0; // Start in preset mode
- varNextColour = 0; //
- varNextColourPrev = 0; // Set Button State
- varBlendingMode = 1; // Start LINEARBLEND
- varUpdatesPerSec = 100; // Start on 100 fps
- varAlertMode = 0; // Start Alert Mode OFF
- varZone = 1;
- /******** FASTLED ************/
- FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
- DebugSerial.begin(9600);
- Serial.begin(9600);
- Blynk.begin(Serial, auth);
- }
- /****************************************************************************/
- // List of patterns to cycle through. Each is defined as a separate function below.
- typedef void (*SimplePatternList[])();
- SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, whitescan };
- 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(V0) {
- if ( (varZone == HardwareZone) || (varZone == 1)) {
- varHue = param.asInt();
- //terminal.print(nickname);
- //terminal.print(" | Hue: ");
- //terminal.println(varHue);
- //terminal.flush();
- //HexRGB = ((long)leds[0].r << 16) | ((long)leds[0].g << 8 ) | (long)leds[0].b;
- //Blynk.setProperty(V0, "color", "#" + String(HexRGB, HEX));
- }
- }
- BLYNK_WRITE(V1) {
- if ( (varZone == HardwareZone) || (varZone == 1)) {
- varSaturation = param.asInt();
- //terminal.print(nickname);
- //terminal.print(" | Saturation: ");
- //terminal.println(varSaturation);
- //terminal.flush();
- }
- }
- BLYNK_WRITE(V2) {
- if ( (varZone == HardwareZone) || (varZone == 1)) {
- varBrightness = param.asInt();
- //terminal.print(nickname);
- //terminal.print(" | Brightness: ");
- //terminal.println(varBrightness);
- //terminal.flush();
- }
- }
- BLYNK_WRITE(V3) {
- if ( (varZone == HardwareZone) || (varZone == 1)) {
- varNextColour = param.asInt();
- if (varNextColour == 1 && varNextColourPrev == 0) {
- nextPattern();
- //terminal.print(nickname);
- //terminal.println(" | Next Colour Pattern");
- //terminal.flush();
- delay(10);
- }
- varNextColourPrev = varNextColour;
- }
- }
- BLYNK_WRITE(V4) {
- if ( (varZone == HardwareZone) || (varZone == 1)) {
- varManualMode = 1;
- Blynk.virtualWrite(V10, varManualMode);
- varBrightness = (int)255;
- Blynk.virtualWrite(V2, 255);
- varSaturation = (int)255;
- Blynk.virtualWrite(V1, 255);
- varHue = (int)152;
- Blynk.virtualWrite(V0, 152);
- //terminal.print(nickname);
- //terminal.println(" | Blue");
- //terminal.flush();
- delay(10);
- }
- }
- BLYNK_WRITE(V5) {
- if ( (varZone == HardwareZone) || (varZone == 1)) {
- varUpdatesPerSec = param.asInt();
- //terminal.print(nickname);
- //terminal.print(" | Updates Per Sec: ");
- //terminal.println(varUpdatesPerSec);
- //terminal.flush();
- }
- }
- BLYNK_WRITE(V6) {
- if ( (varZone == HardwareZone) || (varZone == 1)) {
- varManualMode = 1;
- Blynk.virtualWrite(V10, varManualMode);
- varBrightness = (int)255;
- Blynk.virtualWrite(V2, 255);
- varSaturation = (int)255;
- Blynk.virtualWrite(V1, 255);
- varHue = (int)0;
- Blynk.virtualWrite(V0, 0);
- //terminal.print(nickname);
- //terminal.println(" | Red");
- //terminal.flush();
- delay(10);
- }
- }
- BLYNK_WRITE(V7) {
- if ( (varZone == HardwareZone) || (varZone == 1)) {
- varManualMode = 1;
- Blynk.virtualWrite(V10, varManualMode);
- varBrightness = (int)255;
- Blynk.virtualWrite(V2, 255);
- varSaturation = (int)255;
- Blynk.virtualWrite(V1, 255);
- varHue = (int)80;
- Blynk.virtualWrite(V0, 80);
- //terminal.print(nickname);
- //terminal.println(" | Green");
- //terminal.flush();
- delay(10);
- }
- }
- BLYNK_WRITE(V8) {
- if ( (varZone == HardwareZone) || (varZone == 1)) {
- varManualMode = 1;
- Blynk.virtualWrite(V10, varManualMode);
- varBrightness = (int)255;
- Blynk.virtualWrite(V2, 255);
- varSaturation = (int)0;
- Blynk.virtualWrite(V1, 0);
- //terminal.print(nickname);
- //terminal.println(" | White");
- //terminal.flush();
- delay(10);
- }
- }
- BLYNK_WRITE(V10) {
- if ( (varZone == HardwareZone) || (varZone == 1)) {
- varManualMode = param.asInt();
- //terminal.print(nickname);
- //terminal.print(" | Manual Mode: ");
- if (varManualMode == 0) {
- //terminal.println("OFF");
- }
- if (varManualMode == 1) {
- //terminal.println("ON");
- }
- //terminal.flush();
- }
- }
- BLYNK_WRITE(V11) {
- gHue = 0;
- }
- BLYNK_WRITE(V15) {
- if ( (varZone == HardwareZone) || (varZone == 1)) {
- varManualMode = 1;
- Blynk.virtualWrite(V10, varManualMode);
- varBrightness = (int)255;
- Blynk.virtualWrite(V2, 255);
- varSaturation = (int)255;
- Blynk.virtualWrite(V1, 255);
- varHue = (int)27;
- Blynk.virtualWrite(V0, 27);
- //terminal.print(nickname);
- //terminal.println(" | Orange");
- //terminal.flush();
- delay(10);
- }
- }
- BLYNK_WRITE(V12) {
- if ( (varZone == HardwareZone) || (varZone == 1)) {
- varManualMode = 1;
- Blynk.virtualWrite(V10, varManualMode);
- varBrightness = (int)255;
- Blynk.virtualWrite(V2, 255);
- varSaturation = (int)255;
- Blynk.virtualWrite(V1, 255);
- varHue = (int)64;
- Blynk.virtualWrite(V0, 64);
- //terminal.print(nickname);
- //terminal.println(" | Yellow");
- //terminal.flush();
- delay(10);
- }
- }
- BLYNK_WRITE(V13) {
- varAlertMode = param.asInt();
- }
- BLYNK_WRITE(V14) {
- if ( (varZone == HardwareZone) || (varZone == 1)) {
- varManualMode = 1;
- Blynk.virtualWrite(V10, varManualMode);
- varBrightness = (int)0;
- Blynk.virtualWrite(V2, 0);
- //terminal.print(nickname);
- //terminal.println(" | OFF");
- //terminal.flush();
- delay(10);
- }
- }
- BLYNK_WRITE(V23) {
- varZone = param.asInt();
- if (varZone == HardwareZone) {
- Blynk.virtualWrite(V0, varHue);
- Blynk.virtualWrite(V1, varSaturation);
- Blynk.virtualWrite(V2, varBrightness);
- Blynk.virtualWrite(V5, varUpdatesPerSec);
- Blynk.virtualWrite(V10, varManualMode);
- }
- }
- /****************************************************************************/
- void loop()
- {
- Blynk.run();
- if (varAlertMode == 1) {
- for (int i = 0; i < 20; i++) {
- fill_solid(leds, NUM_LEDS, CRGB::White);
- FastLED.show();
- FastLED.delay(50);
- fill_solid(leds, NUM_LEDS, CRGB::Black);
- FastLED.show();
- FastLED.delay(50);
- }
- varAlertMode = 0;
- }
- if (varManualMode == 1) { // Manual Control
- fill_solid(leds, NUM_LEDS, CHSV(varHue, varSaturation, varBrightness));
- }
- if (varManualMode == 0) { // Pallette Mode
- // Call the current pattern function once, updating the 'leds' array
- gPatterns[gCurrentPatternNumber]();
- FastLED.show();
- FastLED.delay(1000 / varUpdatesPerSec);
- EVERY_N_MILLISECONDS( 20 ) {
- gHue++; // slowly cycle the "base color" through the rainbow
- }
- }
- FastLED.show();
- }
- /****************************************************************************/
- #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 rainbow() {
- // FastLED's built-in rainbow generator
- fill_rainbow( leds, NUM_LEDS, gHue, 7);
- }
- void rainbowWithGlitter() {
- // built-in FastLED rainbow, plus some random sparkly glitter
- rainbow();
- addGlitter(80);
- }
- void addGlitter( fract8 chanceOfGlitter) {
- if ( random8() < chanceOfGlitter) {
- leds[ random16(NUM_LEDS) ] += CRGB::White;
- }
- }
- void confetti() {
- // random colored speckles that blink in and fade smoothly
- fadeToBlackBy( leds, NUM_LEDS, 10);
- int pos = random16(NUM_LEDS);
- leds[pos] += CHSV( gHue + random8(64), 200, 255);
- }
- 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 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;
- }
- }
- void whitescan() {
- for (int i = 0; i < NUM_LEDS; i++) {
- leds[i] = CRGB::White;
- FastLED.show();
- FastLED.delay(1000 / varUpdatesPerSec);
- leds[i] = CRGB::Black;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement