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

Timer in blynk

esp8266

#1
#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <TimeLib.h>
#include <WidgetRTC.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

char ssid[] = "xxxx";
char pass[] = "xxxxxxxxxxxxxx";


BlynkTimer timer;

WidgetRTC rtc;

// Digital clock display of the time
void clockDisplay()
{
  // You can call hour(), minute(), ... at any time
  // Please see Time library examples for details

  String currentTime = String(hour()) + " : " + minute() + " : " + second();
  String currentDate = String(day()) + " / " + month() + " / " + year();
  Serial.print("Current time: ");
  Serial.print(currentTime);
  Serial.print(" ");
  Serial.print(currentDate);
  Serial.println();
  
  Blynk.virtualWrite(V1, currentTime);
  Blynk.virtualWrite(V2, currentDate);
}

//void slem()
//{
  //if(digitalRead(D0)==LOW){
  //(Blynk.virtualWrite(V5, 0));
  //}else{
  //(Blynk.virtualWrite(V5, 255));
  //}
  //if(digitalRead(D5)==LOW){
  //(Blynk.virtualWrite(V6, 0));
  //}else{
  //(Blynk.virtualWrite(V6, 255));
  //}
//}





void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  rtc.begin();
  timer.setInterval(1000L, clockDisplay);
}


void loop()
  {
  if(digitalRead(D0)==LOW){
  (Blynk.virtualWrite(V5, 0));
  }else{
  (Blynk.virtualWrite(V5, 255));
  }
  if(digitalRead(D5)==LOW){
  (Blynk.virtualWrite(V6, 0));
  }else{
  (Blynk.virtualWrite(V6, 255));
  }
  Blynk.run();
  timer.run();
}

lamp on start timer
lamp off stop


#2

Hello… Welcome to the Blynk forum.

First off… as per the directions that you deleted when posting (you did read them first… correct? :wink: )… you must properly format all posted code for proper forum viewing…

Blynk - FTFC

Then do so :stuck_out_tongue: we will point you in the right direction, but you need to do the thinking.

And without much more details we don’t understand why you want a timer that only works this way… since what you are trying to do matters to the type of timer you want to use and how you set it up…

https://playground.arduino.cc/Code/SimpleTimer#Functions


#3

:scream::scream::scream::scream::scream:


#4

@Alexis_Cabrera OP edited the comment (made it even less informative :man_facepalming: ) but didn’t format the code… so I don’t even bother to look closely at unformatted code :stuck_out_tongue: But now that you have pointed that out… yep, too scary :scream:


#5

@Gunner hmmm, when I start with blynk , I always made the same mistake since you explained me :wink:


#6

Well the OPi hasn’t logged back in since, so I formatted the code… but I think the rest is up to the OP or some gracious user with lots of time :slight_smile: