"SmartLED Controller" - ESP+FastLED+Blynk (Video)

I havn’t looked in to yet too… also post it here if you find a fix :slight_smile:

I am currently working on a memory button. It will save the vars to some empty virtual ports in the 90-99 range and pull them back on command.

But I really like your code! I am happy I don’t need to start at ground zero.

Also I am happy you have put the dashboard online😁

I made a few changes and added the wake up feature.

/*
  Virtual Ports:
  V0 = Hue (Slider 0-255)
  V1 = Saturation (Slider 0-255)
  V2 = Brightness (Slider 0-255)
  V3 = Cycle Pre-set (Momentary Button)
  V4 = Colour: Blue (Momentary Button)
  V5 = Updates Per Sec (Slider 1-500)
  V6 = Colour: Red (Momentary Button)
  V7 = Colour: Green (Momentary Button)
  V8 = Colour: White (Momentary Button)
  V9 = Terminal Widget
  V10 = Manual Mode (Switch Button)
  V11 = Sync gHUE (Momentary Button)
  V12 = Colour: Yellow (Momentary Button)
  V13 = Alert Mode (Momentary Button)
  V14 = OFF (Momentary Button)
  V15 = Colour: Light Blue (Momentary Button)
  V16 = Shelf Up Time (Value Widget)
  V17 = Shelf Wifi Signal (Value Widget)
  V18 = Slave 1 Up Time (Value Widget)
  V19 = Slave 1 Wifi Signal (Value Widget) optional
  V20 = Slave 2 Up Time (Value Widget) optional
  V21 = Slave 2 Wifi Signal (Value Widget) optional
  V22 = Rainbow Mode Speed/Blend (Slider Widget range= -4 through +4
  V29 = Night Mode
*/
/****************************************************************************/
#define BLYNK_PRINT Serial
#include <ArduinoOTA.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <FastLED.h>
#include <SimpleTimer.h>

/****************************************************************************/
#define BLYNK_MSG_LIMIT    200
#define DATA_PIN           D6
/************************ CHANGE SETTINGS HERE ONLY *************************/
#define NUM_LEDS 150
char nickname[] = "LED1";
int HardwareZone = 2; // OUTDOOR // DONT USE 0 or 1 ... CAUSES ERRORS WITH LOGIC
char auth[] = "xxxx";
/****************************************************************************/
int varHue;
int varHuePrev;
int varHueNew;
int varSaturation;
int varBrightness;
int varManualMode;
int varNextColour;
int varNextColourPrev;
int varBlendingMode;
int varUpdatesPerSec;
int varAlertMode;
int varZone;
int varRainbowSpeed;
long HexRGB;
int curMode;
int curSaturation;
int curBrightness;
int curHue;

int varBrightnessPrev;
boolean varManualModePrev;
boolean alarmToggle;
boolean alarmTrigger;
int alarmHue; 
int alarmSaturation; 
int alarmBrightness; 
double timeOfFade;
boolean wakeUpModeON = false; //Blocks RGB Control during alarm !ONLY IN CODE NOT IN BLYNK-APP!
boolean wakeUpFirstStart = true; // Makes settings for first start wakeUpModeON.
double fadeStep;
boolean previewAlarm;
/****************************************************************************/
WidgetTerminal terminal(V9);
SimpleTimer timer;
SimpleTimer alarmTimer;
int alarm1;

CRGB leds[NUM_LEDS];
/****************************************************************************/
void sendUptime() {
  Blynk.virtualWrite(V16, millis() / 1000);
  Blynk.virtualWrite(V17, map(WiFi.RSSI(), -105, -40, 0, 100) );
}
/****************************************************************************/
void setup()
{
  WiFi.mode(WIFI_STA);
  //Blynk.begin(auth, "xxxxxx", "xxxxxx", IPAddress(192, 168, 1, 2)); // my own local server
  Blynk.begin(auth, "onsthuis-1", "xxxxxx", "RASPBERRYPI");
  while (Blynk.connect() == false) {}
  Blynk.syncAll();
  /*********** OTA *************/
  ArduinoOTA.setHostname("ESP-LED-01");
  ArduinoOTA.begin();
  /******** BOOT VARS **********/
  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;
  varRainbowSpeed = 0;    // Start stationary
  /******** FASTLED ************/
  FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS);
  /******** READY **************/
  terminal.print(F("# Blynk v" BLYNK_VERSION ": "));
  terminal.print(nickname);
  terminal.println(F(" Device started"));
  terminal.flush();
  timer.setInterval(1000L, sendUptime);
}
/****************************************************************************/
// List of patterns to cycle through.  Each is defined as a separate function below.
typedef void (*SimplePatternList[])();
SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle };
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();
    //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();
  }
}
BLYNK_WRITE(V2) {
  if ( (varZone == HardwareZone) || (varZone == 1)) {
    varBrightness = param.asInt();
  }
}
BLYNK_WRITE(V3) {
  if ( (varZone == HardwareZone) || (varZone == 1)) {
    varNextColour = param.asInt();
    if (varNextColour == 1 && varNextColourPrev == 0) {
      nextPattern();
      delay(10);
    }
    varNextColourPrev = varNextColour;
  }
}
BLYNK_WRITE(V4) {
  if ( (varZone == HardwareZone) || (varZone == 1)) {
    varManualMode = 1;
    varHue        = (int)152;
    Blynk.virtualWrite(V10, varManualMode);
    Blynk.virtualWrite(V2, varBrightness);
    Blynk.virtualWrite(V1, varSaturation);
    Blynk.virtualWrite(V0, 152);
    delay(10);
  }
}
BLYNK_WRITE(V5) {
  if ( (varZone == HardwareZone) || (varZone == 1)) {
    varUpdatesPerSec = param.asInt();
  }
}
BLYNK_WRITE(V6) {
  if ( (varZone == HardwareZone) || (varZone == 1)) {
    varManualMode = 1;
    varHue        = (int)0;
    Blynk.virtualWrite(V10, varManualMode);
    Blynk.virtualWrite(V2, varBrightness);
    Blynk.virtualWrite(V1, varSaturation);
    Blynk.virtualWrite(V0, 0);
    delay(10);
  }
}
BLYNK_WRITE(V7) {
  if ( (varZone == HardwareZone) || (varZone == 1)) {
    varManualMode = 1;
    varHue        = (int)80;
    Blynk.virtualWrite(V10, varManualMode);
    Blynk.virtualWrite(V2, varBrightness);
    Blynk.virtualWrite(V1, varSaturation);
    Blynk.virtualWrite(V0, 80);
    delay(10);
  }
}
BLYNK_WRITE(V8) {
  if ( (varZone == HardwareZone) || (varZone == 1)) {
    varManualMode = 1;
    varSaturation = (int)0;
    Blynk.virtualWrite(V10, varManualMode);
    Blynk.virtualWrite(V2, varBrightness);
    Blynk.virtualWrite(V1, 0);
    delay(10);
  }
}
BLYNK_WRITE(V10) {
  if ( (varZone == HardwareZone) || (varZone == 1)) {
    varManualMode = param.asInt();
    if (varManualMode == 1){
      previewAlarm = LOW;
      Blynk.virtualWrite(35, LOW);
    }
  }
}
BLYNK_WRITE(V11) {
  gHue = 0;
  terminal.print(nickname);
  terminal.println(" | Sync'd gHUE ");
  terminal.flush();
}

BLYNK_WRITE(V15) {
  if ( (varZone == HardwareZone) || (varZone == 1)) {
    varManualMode = 1;
    Blynk.virtualWrite(V10, varManualMode);
    varHue        = (int)27;
    Blynk.virtualWrite(V2, varBrightness);
    Blynk.virtualWrite(V1, varSaturation);
    Blynk.virtualWrite(V0, 27);
    delay(10);
  }
}

BLYNK_WRITE(V12) {
  if ( (varZone == HardwareZone) || (varZone == 1)) {
    varManualMode = 1;
    varHue        = (int)64;
    Blynk.virtualWrite(V10, varManualMode);
    Blynk.virtualWrite(V2, varBrightness);
    Blynk.virtualWrite(V1, varSaturation);
    Blynk.virtualWrite(V0, 64);
    delay(10);
  }
}

BLYNK_WRITE(V13) {
  varAlertMode = param.asInt();
  terminal.print(nickname);
  terminal.println(" | ALERT!");
  terminal.flush();
}

BLYNK_WRITE(V14) {
  if ( (varZone == HardwareZone) || (varZone == 1)) {
    varManualMode = 1;
    varBrightness = (int)0;
    Blynk.virtualWrite(V10, varManualMode);
    Blynk.virtualWrite(V2, 0);
//    delay(10);
  }
}

BLYNK_WRITE(V22) {
  if ( (varZone == HardwareZone) || (varZone == 1)) {
    varRainbowSpeed = param.asInt();
    Blynk.virtualWrite(V22, varRainbowSpeed);
  }
}

BLYNK_WRITE(V23) {
  varZone = param.asInt();
  if (varZone == HardwareZone) {
    terminal.print(nickname);
    terminal.println(" | Zone Selected!");
    terminal.flush();
    Blynk.virtualWrite(V0,  varHue);
    Blynk.virtualWrite(V1,  varSaturation);
    Blynk.virtualWrite(V2,  varBrightness);
    Blynk.virtualWrite(V5,  varUpdatesPerSec);
    Blynk.virtualWrite(V10, varManualMode);
    Blynk.virtualWrite(V22, varRainbowSpeed);
  }
}
BLYNK_WRITE(V29) {
  alarmTrigger = param.asInt();
  if (alarmToggle == HIGH && alarmTrigger == HIGH){
    varBrightness = (int)0;
    Blynk.virtualWrite(V2, varBrightness);
    wakeUpModeON = true;
    wakeUpMode();
  }
  if (alarmTrigger == LOW || alarmToggle == LOW){
    wakeUpFirstStart = true;
    wakeUpModeON = false;
  }
  
}
BLYNK_WRITE(V30) {
  alarmToggle = param.asInt();
  if (alarmToggle == LOW || alarmTrigger == LOW){
    wakeUpFirstStart = true;
    wakeUpModeON = false;
    alarmTimer.deleteTimer(alarm1);
  }
}

BLYNK_WRITE(V31) {
  alarmHue = param.asInt(); 

}

BLYNK_WRITE(V36) {
  alarmSaturation = param.asInt(); 
}

BLYNK_WRITE(V33) {
  alarmBrightness = param.asInt();
  if (previewAlarm==HIGH){
   varBrightness = alarmBrightness;
   Blynk.virtualWrite(2, alarmBrightness); 
  }
}

BLYNK_WRITE(V34) {
  timeOfFade = param.asInt() * 60; // Writes time of fade to seconds

}
BLYNK_WRITE(V35) {
  previewAlarm = param.asInt();
  if(previewAlarm ==HIGH){
    varManualModePrev = varManualMode;
    varBrightnessPrev = varBrightness;
    varManualMode = false;
    Blynk.virtualWrite(10, varManualMode);
    
  }
  if(previewAlarm ==LOW){
    varManualMode = varManualModePrev;
    varBrightness = varBrightnessPrev;
    Blynk.virtualWrite(10, varManualMode);
  }
  
}
/****************************************************************************/

void wakeUpMode() {
  if (wakeUpModeON = true) {
    varManualMode = HIGH;
    Blynk.virtualWrite(10, varManualMode);
    if (wakeUpFirstStart == true) {
      fadeStep = alarmBrightness / timeOfFade;
      wakeUpFirstStart = false;
      int alarm1 = alarmTimer.setTimer(1000, alarmFader, timeOfFade);
      alarmTimer.enable(alarm1);
    }
  }
}

//FADING

void alarmFader() {
  varBrightness += fadeStep;
  Blynk.virtualWrite(V2, varBrightness);
}


/****************************************************************************/
void loop()
{
  Blynk.run();
  ArduinoOTA.handle();
  timer.run(); // Initiates SimpleTimer
  alarmTimer.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 && alarmTrigger == LOW) { // Manual Control
    fill_solid(leds, NUM_LEDS, CHSV(varHue, varSaturation, varBrightness));
  }
  if (varManualMode == 0 && (alarmTrigger == HIGH || previewAlarm == HIGH)) { // Manual Control
    fill_solid(leds, NUM_LEDS, CHSV(alarmHue, alarmSaturation, varBrightness));
  }

  if (varManualMode == 0 && alarmTrigger == LOW && previewAlarm == LOW) { // Pallette Mode
    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, varRainbowSpeed);
}

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), varSaturation, varBrightness);
}

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, varSaturation, varBrightness);
}

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, varSaturation, varBrightness);
    dothue += 32;
  }
}

1 Like

I don’t know how to get rid of this delay.
This will cause the connection loss when you want to change the movement speed to a slow movement. The whole code will be delayed and the blynk app has a delay/crash.

I tried to work with a Simple timer, but I didn’t get this right.

To get around this I have changed the heart beat timeout in the Library using this method.

1 Like

My new working version of the app.

/*
  Virtual Ports:
  V0 = Hue (Slider 0-255)
  V1 = Saturation (Slider 0-255)
  V2 = Brightness (Slider 0-255)
  V3 = Cycle Pre-set (Momentary Button)
  V4 = Colour: Blue (Momentary Button)
  V5 = Updates Per Sec (Slider 1-500)
  V6 = Colour: Red (Momentary Button)
  V7 = Colour: Green (Momentary Button)
  V8 = Colour: White (Momentary Button)
  V9 = Terminal Widget
  V10 = Manual Mode (Switch Button)
  V11 = Sync gHUE (Momentary Button)
  V12 = Colour: Yellow (Momentary Button)
  V13 = Alert Mode (Momentary Button)
  V14 = OFF (Momentary Button)
  V15 = Colour: Light Blue (Momentary Button)
  V16 = Shelf Up Time (Value Widget)
  V17 = Shelf Wifi Signal (Value Widget)
  V18 = Slave 1 Up Time (Value Widget)
  V19 = Slave 1 Wifi Signal (Value Widget) optional
  V20 = Slave 2 Up Time (Value Widget) optional
  V21 = Slave 2 Wifi Signal (Value Widget) optional
  V22 = Rainbow Mode Speed/Blend (Slider Widget range= -4 through +4
  V29 = Night Mode
*/
/****************************************************************************/
#define BLYNK_PRINT Serial
#include <ArduinoOTA.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <FastLED.h>
#include <SimpleTimer.h>
//#include <WidgetRTC.h>
/**********************WEBSERVER UPLOAD************************************************/
#include <ESP8266mDNS.h>
#include <ESP8266HTTPUpdateServer.h>
#include <ESP8266WebServer.h>

ESP8266WebServer httpServer(80);
ESP8266HTTPUpdateServer httpUpdater;

/****************************************************************************/
#define BLYNK_MSG_LIMIT    200
#define DATA_PIN           D6
/************************ CHANGE SETTINGS HERE ONLY *************************/
#define NUM_LEDS 150
char nickname[] = "LED1";
int HardwareZone = 2; // OUTDOOR // DONT USE 0 or 1 ... CAUSES ERRORS WITH LOGIC
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
/****************************************************************************/
int varHue;
int varHuePrev;
int varHueNew;
int varSaturation;
float varBrightness;
int varManualMode;
int varNextColour;
int varNextColourPrev;
int varBlendingMode;
int varUpdatesPerSec;
int varAlertMode;
int varZone;
int varRainbowSpeed;
long HexRGB;
int curMode;
int curSaturation;
int curBrightness;
int curHue;

int varBrightnessPrev;
boolean varManualModePrev;
boolean alarmToggle = 1;
boolean alarmTrigger = 0;
int alarmHue = 20;
int alarmSaturation = 200;
float alarmBrightness = 255.00000;
float timeOfFade = 60.00000;
boolean wakeUpModeON = false; //Blocks RGB Control during alarm !ONLY IN CODE NOT IN BLYNK-APP!
boolean wakeUpFirstStart = true; // Makes settings for first start wakeUpModeON.
float fadeStep = 0.00000;
boolean previewAlarm;

//WidgetRTC rtc;
//
//BLYNK_ATTACH_WIDGET(rtc, V24);
/****************************************************************************/
WidgetTerminal terminal(V9);
SimpleTimer timer;
SimpleTimer alarmTimer;
//SimpleTimer updateTimer;
int alarm1;

CRGB leds[NUM_LEDS];
/****************************************************************************/
void sendUptime() {
  Blynk.virtualWrite(V16, millis() / 1000);
  Blynk.virtualWrite(V17, map(WiFi.RSSI(), -105, -40, 0, 100) );
}
/****************************************************************************/
void setup()
{
  WiFi.mode(WIFI_STA);
  //Blynk.begin(auth, "xxxxxx", "xxxxxx", IPAddress(192, 168, 1, 2)); // my own local server
  Blynk.begin(auth, "xxxxxxxxx", "xxxxxxx", "RASPBERRYPI");
  while (Blynk.connect() == false) {}

  /*********** OTA *************/
  ArduinoOTA.setHostname("ESP-LED-01");
  ArduinoOTA.begin();

  /*********** OTA uploader webserver *************/
  MDNS.begin("ESP-LED-01");

  httpUpdater.setup(&httpServer);
  httpServer.begin();

  MDNS.addService("http", "tcp", 80);
  /******** BOOT VARS **********/
  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 = 128; // Start on 100 fps
  varAlertMode = 0;       // Start Alert Mode OFF
  varZone = 1;
  varRainbowSpeed = 0;    // Start stationary
  /******** FASTLED ************/
  FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS);
  /******** READY **************/
  terminal.print(F("# Blynk v" BLYNK_VERSION ": "));
  terminal.print(nickname);
  terminal.println(F(" Device started"));
  terminal.flush();
  timer.setInterval(1000L, sendUptime);
  Blynk.syncAll();
  //  rtc.begin();
}
/****************************************************************************/
// List of patterns to cycle through.  Each is defined as a separate function below.
typedef void (*SimplePatternList[])();
SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle };
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();
    //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();
  }
}
BLYNK_WRITE(V2) {
  if ( (varZone == HardwareZone) || (varZone == 1)) {
    varBrightness = param.asInt();
  }
}
BLYNK_WRITE(V3) {
  if ( (varZone == HardwareZone) || (varZone == 1)) {
    varNextColour = param.asInt();
    if (varNextColour == 1 && varNextColourPrev == 0) {
      nextPattern();
      delay(10);
    }
    varNextColourPrev = varNextColour;
  }
}
BLYNK_WRITE(V4) {
  if ( (varZone == HardwareZone) || (varZone == 1)) {
    varManualMode = 1;
    varHue        = (int)152;
    Blynk.virtualWrite(V10, varManualMode);
    Blynk.virtualWrite(V2, varBrightness);
    Blynk.virtualWrite(V1, varSaturation);
    Blynk.virtualWrite(V0, 152);
    delay(10);
  }
}
BLYNK_WRITE(V5) {
  if ( (varZone == HardwareZone) || (varZone == 1)) {
    varUpdatesPerSec = param.asInt();
    //    varUpdatesPerSec = 1000 / varUpdatesPerSec;

  }
}
BLYNK_WRITE(V6) {
  if ( (varZone == HardwareZone) || (varZone == 1)) {
    varManualMode = 1;
    varHue        = (int)0;
    Blynk.virtualWrite(V10, varManualMode);
    Blynk.virtualWrite(V2, varBrightness);
    Blynk.virtualWrite(V1, varSaturation);
    Blynk.virtualWrite(V0, 0);
    delay(10);
  }
}
BLYNK_WRITE(V7) {
  if ( (varZone == HardwareZone) || (varZone == 1)) {
    varManualMode = 1;
    varHue        = (int)80;
    Blynk.virtualWrite(V10, varManualMode);
    Blynk.virtualWrite(V2, varBrightness);
    Blynk.virtualWrite(V1, varSaturation);
    Blynk.virtualWrite(V0, 80);
    delay(10);
  }
}
BLYNK_WRITE(V8) {
  if ( (varZone == HardwareZone) || (varZone == 1)) {
    varManualMode = 1;
    varSaturation = (int)0;
    Blynk.virtualWrite(V10, varManualMode);
    Blynk.virtualWrite(V2, varBrightness);
    Blynk.virtualWrite(V1, 0);
    delay(10);
  }
}
BLYNK_WRITE(V10) {
  if ( (varZone == HardwareZone) || (varZone == 1)) {
    varManualMode = param.asInt();
    if (varManualMode == 1) {
      previewAlarm = LOW;
      Blynk.virtualWrite(35, LOW);
    }
  }
}
BLYNK_WRITE(V11) {
  gHue = 0;
  terminal.print(nickname);
  terminal.println(" | Sync'd gHUE ");
  terminal.flush();
}

BLYNK_WRITE(V15) {
  if ( (varZone == HardwareZone) || (varZone == 1)) {
    varManualMode = 1;
    Blynk.virtualWrite(V10, varManualMode);
    varHue        = (int)27;
    Blynk.virtualWrite(V2, varBrightness);
    Blynk.virtualWrite(V1, varSaturation);
    Blynk.virtualWrite(V0, 27);
    delay(10);
  }
}

BLYNK_WRITE(V12) {
  if ( (varZone == HardwareZone) || (varZone == 1)) {
    varManualMode = 1;
    varHue        = (int)64;
    Blynk.virtualWrite(V10, varManualMode);
    Blynk.virtualWrite(V2, varBrightness);
    Blynk.virtualWrite(V1, varSaturation);
    Blynk.virtualWrite(V0, 64);
    delay(10);
  }
}

BLYNK_WRITE(V13) {
  varAlertMode = param.asInt();
  terminal.print(nickname);
  terminal.println(" | ALERT!");
  terminal.flush();
}

BLYNK_WRITE(V14) {
  if ( (varZone == HardwareZone) || (varZone == 1)) {
    varManualMode = 1;
    varBrightness = (int)0;
    Blynk.virtualWrite(V10, varManualMode);
    Blynk.virtualWrite(V2, 0);
    delay(10);
  }
}

BLYNK_WRITE(V22) {
  if ( (varZone == HardwareZone) || (varZone == 1)) {
    varRainbowSpeed = param.asInt();
    Blynk.virtualWrite(V22, varRainbowSpeed);
  }
}

BLYNK_WRITE(V23) {
  varZone = param.asInt();
  if (varZone == HardwareZone) {
    terminal.print(nickname);
    terminal.println(" | Zone Selected!");
    terminal.flush();
    Blynk.virtualWrite(V0,  varHue);
    Blynk.virtualWrite(V1,  varSaturation);
    Blynk.virtualWrite(V2,  varBrightness);
    Blynk.virtualWrite(V5,  varUpdatesPerSec);
    Blynk.virtualWrite(V10, varManualMode);
    Blynk.virtualWrite(V22, varRainbowSpeed);
  }
}
BLYNK_WRITE(V28) {
  alarmTrigger = param.asInt();
  alarmMode();
}
BLYNK_WRITE(V27) {
  alarmTrigger = param.asInt();
  alarmMode();
}



BLYNK_WRITE(V30) {
  alarmToggle = param.asInt();
  if (alarmToggle == LOW || alarmTrigger == LOW) {
    wakeUpFirstStart = true;
    wakeUpModeON = false;
    alarmTimer.deleteTimer(alarm1);
  }
}

BLYNK_WRITE(V31) {
  alarmHue = param.asInt();

}

BLYNK_WRITE(V36) {
  alarmSaturation = param.asInt();
}

BLYNK_WRITE(V33) {
  alarmBrightness = param.asInt();
  if (previewAlarm == HIGH) {
    varBrightness = alarmBrightness;
    Blynk.virtualWrite(2, alarmBrightness);
  }
}

BLYNK_WRITE(V34) {
  timeOfFade = param.asInt() * 60; // Writes time of fade to seconds
  terminal.print("timeOfFade: ");
  terminal.println(timeOfFade);
  terminal.flush();
}
BLYNK_WRITE(V35) {
  previewAlarm = param.asInt();
  if (previewAlarm == HIGH) {
    varManualModePrev = varManualMode;
    varBrightnessPrev = varBrightness;
    varBrightness = alarmBrightness;
    varManualMode = false;
    Blynk.virtualWrite(10, varManualMode);


  }
  if (previewAlarm == LOW) {
    varManualMode = varManualModePrev;
    varBrightness = varBrightnessPrev;
    Blynk.virtualWrite(10, varManualMode);
  }

}
/****************************************************************************/
void alarmMode(){
  if (alarmToggle == HIGH && alarmTrigger == HIGH) {
    varBrightness = (int)0;
    Blynk.virtualWrite(V2, varBrightness);
    wakeUpModeON = true;
    wakeUpMode();
  }
  if (alarmTrigger == LOW || alarmToggle == LOW) {
    wakeUpFirstStart = true;
    wakeUpModeON = false;
    alarmTimer.deleteTimer(alarm1);

  }
}
//  TimeInputParam t(param);
//
//  if (t.hasStartTime()) {
//  alarmTrigger == HIGH;
//  if (alarmToggle == HIGH && alarmTrigger == HIGH) {
//      varBrightness = (int)0;
//      Blynk.virtualWrite(V2, varBrightness);
//      wakeUpModeON = true;
//      wakeUpMode();
//    }
//  }
//  if (t.hasStopTime()) {
//  alarmTrigger == LOW;
//  if (alarmTrigger == LOW || alarmToggle == LOW) {
//      wakeUpFirstStart = true;
//      wakeUpModeON = false;
//      alarmTimer.deleteTimer(alarm1);
//    }
//  }
//}
void wakeUpMode() {
  if (wakeUpModeON = true) {
    varManualMode = LOW;
    Blynk.virtualWrite(10, varManualMode);
    if (wakeUpFirstStart == true) {
      fadeStep = alarmBrightness / timeOfFade;
      terminal.print("fadeStep: ");
      terminal.print(fadeStep);
      wakeUpFirstStart = false;
      int alarm1 = alarmTimer.setTimer(1000, alarmFader, timeOfFade);
      alarmTimer.enable(alarm1);
    }
  }
}

//FADING

void alarmFader() {
  varBrightness += fadeStep;
  Blynk.virtualWrite(V2, varBrightness);
  terminal.flush();
}

//void updatePerSec() {
//  gPatterns[gCurrentPatternNumber]();
//  FastLED.show();
//  EVERY_N_MILLISECONDS( 20 ) {
//    gHue++;  // slowly cycle the "base color" through the rainbow
//  }
//FastLED.show();
//}
/****************************************************************************/
void loop()
{
  Blynk.run();
  ArduinoOTA.handle();
  httpServer.handleClient(); 
  timer.run(); // Initiates SimpleTimer
  alarmTimer.run();
  //  updateTimer.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 && (alarmTrigger == LOW || alarmToggle == LOW)) { // Manual Control
    fill_solid(leds, NUM_LEDS, CHSV(varHue, varSaturation, varBrightness));
    FastLED.show();
  }
  if (varManualMode == 0 && ((alarmTrigger == HIGH && alarmToggle == HIGH) || previewAlarm == HIGH)) { // Manual Control
    fill_solid(leds, NUM_LEDS, CHSV(alarmHue, alarmSaturation, varBrightness));
    FastLED.show();
  }

  if (varManualMode == 0 && (alarmTrigger == LOW && alarmToggle == LOW) && previewAlarm == LOW) { // Pallette Mode
    gPatterns[gCurrentPatternNumber]();
    FastLED.show();

    //    updateTimer.setInterval(varUpdatesPerSec, updatePerSec);


    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, varRainbowSpeed);
}

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), varSaturation, varBrightness);
}

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, varSaturation, varBrightness);
}

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, varSaturation, varBrightness);
    dothue += 32;
  }
}

please try to sent the link. I can not scan successfully the qr code…

I don’t have a link, it’s from my private server which is only accessible from within my network…

Things like this

int alarm1 = alarmTimer.setTimer(1000, alarmFader, timeOfFade);
alarmTimer.enable(alarm1);

can be replaced with:

alarmTimer.setTimeout(1000, alarmFader, timeOfFade);
1 Like

this qr code is not working for me, is there some other way to load app? Can someone confirm that this qr is all right?

Thanks.

Works fine for me!

QR codes for me also not working.

I have reported this qr code bug to blynk. They said that they will try to fix it in next version.

Sad that after so many updates QR code still can not be scanned.

I’ve just scanned it fine? Maybe be a version mismatch? Im also iOS (which is usualy behind Android)

1 Like

Maybe if you provide more info regarding problem we could fix it?

I tried to scan this QR code from two different monitors from large tv from another phone screen even printed on the paper and nothing happening. When other QR codes can be scanned with no problem Used with autofocus and with fixed focus.
Application: version 2.8.1 (android)
Device: Galaxy s7 Android 6.0.1
Tried with Xiaomi redmi Note 3 and also no luck.

Here is a new QR code:

Same thing… Must be doing something wrong… I’m giving up.

You sure you used scanner for cloning and not for sharing?
Just in case here is the doc: (“Share your Project configuration” section)
http://docs.blynk.cc/#sharing-share-your-project-configuration