BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Thinking blockade with timer

#1

Hey guys, let me present my idea from a smart “way-to-toilet-by-night” illumination. A move detection recognizes if there is something moving, if yes the switching-on process should start. The LED strip fades up (from 0 to 255) while the speed of the fading process should be adjustable ofer Blynk app. When the value reached 255 it keeps shining for a time which is also adjustable than it switches off. To avoid troubles with the rest of the sketch, I get the value from the move detection over interrupt.
The move detection below is simulated by a App push and interrupt comes later :relaxed:
First of all I needed help with my shit :face_vomiting: Func_Nightlight

#include <ESP8266WiFi.h>
#define BLYNK_PRINT Serial
#include <BlynkSimpleEsp8266.h>
#define NEON_GREEN      "#00FF00"
#define BLYNK_GREEN     "#23C48E"
#define BLYNK_BLACK     "#000000"

//WLAN Anmeldung
char auth[] = "--------------------------------";       //Auth Token von Wemos_Inndoor
char ssid[] = "------------";                           //WLAN SSID
char pass[] = "--------------------";                   //WLAN Password

//Variablen Deklaration

const int WemosPin_D3 = 0;                            //LED strip
int Push_Bewegungsmelder = 0;

const int NightlightValue = 0;
int Nightlight_Steps = 5;
int Nightlight_Value = 0;
int TimeON_Nightlight = 3;
int NightlightDelay = 5;
int OutputValue_LEDstrip = 0;
int timerID_Nightlight = 0;
int var_Nightlight = 0;
int Control_Nightlight = 0;                             //slider to change fade speed
int NightlightSteps = 5;
int OutputValue_Nightlight = 0;

WidgetLED LED_LEDstrip(V51);
BlynkTimer timerNightlight;


void setup() {
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  pinMode (WemosPin_D3, OUTPUT);
  timerID_Nightlight = timerNightlight.setInterval(10L, Func_Nightlight);
}

void loop() {
  Blynk.run();
  timerNightlight.run();
}

BLYNK_WRITE(V42) {                                                     //Push Nightlight
  Blynk.setProperty (V42, "onLabel",      "ON");
  Blynk.setProperty (V42, "offLabel",     "OFF");
  Blynk.setProperty (V42, "onColor",      BLYNK_BLACK);
  Blynk.setProperty (V42, "offColor",     BLYNK_BLACK);
  Blynk.setProperty (V42, "onBackColor",  NEON_GREEN);
  Blynk.setProperty (V42, "offBackColor", BLYNK_GREEN);
  Push_Bewegungsmelder = param.asInt();
  if (Push_Bewegungsmelder == 1) {
    var_Nightlight = 1;
    Blynk.virtualWrite (V42, HIGH);
    LED_LEDstrip.on();
  }
}

BLYNK_WRITE(V39)  {                                    //Slider Control Szene (1...50)
  Control_Nightlight = param.asInt();
  if (var_Nightlight == 1) {
    timerNightlight.deleteTimer(timerID_Nightlight);
    timerID_Nightlight = timerNightlight.setInterval(500L / Control_Nightlight, Func_Nightlight);
  }
}

BLYNK_WRITE(V44) {                                            
  TimeON_Nightlight = param.asInt();                          //TimeON LED in ms
  NightlightDelay = (TimeON_Nightlight * 1000);               //TimeON LED in s
}

void Func_Nightlight() {
  if (var_Nightlight == 1) {
    NightlightValue = 0;
    NightlightValue = NightlightValue + NightlightSteps;
    if (NightlightValue >= 255) {
      NightlightValue = 255;
    }
    OutputValue_LEDstrip = OutputValue_Nightlight;
    analogWrite (WemosPin_D3, OutputValue_LEDstrip) ;
  }
  if (var_Nightlight == 255) {
    timer.setTimeout(NightlightDelay, Nightlight_OFF);
  }
}

void Nightlight_OFF() {
  Nightlight_Value = 0;
  OutputValue_LEDstrip = Nightlight_Value;
  analogWrite(WemosPin_D3, OutputValue_LEDstrip);
  LED_LEDstrip.off();
  Blynk.virtualWrite (V42, LOW); 
}
0 Likes

#2

And what is it that you need help with?

Pete.

0 Likes

#3

By fading up, waiting an adjistable time and spending off again :see_no_evil:

0 Likes

#4

Look into using various timers like timeout timers.

0 Likes