Codeing help

Hello again.

wondering if somebody can point me in the right direction with some code. i would like to eventually send a timer like this

long lastTime = 0;
long minutes = 0;
long hours = 0;

void setup() {

}

void loop() {

  if(millis()-lastTime > 60000){
    minutes++;
    lastTime = millis();
  }
  if(minutes > 60){
    hours++;
    minutes = 0;
  }
  

}

to a value display. I can send each variable by itself but i am unsure how to send them all in one go to one input. Unsure if this is even posible.

I think my best bet is to use sprintf but unsure if this is right and how to even use it.

Thanks

You can send an array of variables to a widget with the following syntax:

Blynk.virtualWrite(Vi, x, y, z);

it’s not really clear what you want to do.

Sorry. Was not that clear as i was unsure how i wanted to go about it.

I am wanting to start and reset a timer but if i can just get the timer going for now. There maybe a better way of getting it to work what i have at the moment is as follows.

void fermentTime()
{
  char buffer[100];
  long lastTime = 0;
  long fermMinutes = 0;
  long fermHours = 0;
  long fermDays = 0;
  long fermWeeks = 0;

  if(millis()-lastTime > 60000){
  fermMinutes++;
  lastTime = millis();
  }

  if(fermMinutes > 60){
  fermHours++;
  fermMinutes = 0;
  }

  if(fermHours > 24){
  fermDays++;
  fermHours = 0;
  }

  if(fermDays > 7){
  fermWeeks++;
  fermDays = 0;
  }

  sprintf(buffer, "Fermentation Timer %ld:%ld:%ld", fermHours, fermMinutes, lastTime );
  Serial.println (buffer);
  Blynk.virtualWrite(V15, fermWeeks, fermHours, fermMinutes, lastTime);
  
}

void setup()
{

// Timers
  timer.setInterval(1000, myTimerEvent);    //Send runtime every sec to blynk
  timer.setTimeout(5000, startLCD);         //LCD Start
  timer.setInterval(2000, fermentTime);    //Send runtime every sec to blynk
  timer.setInterval(4000, sendDS18B20);     //Send DS18B20 data every 4 sec to blynk
  // timer.setInterval(5000, sendDHT);         //Send DHT data every 5 sec to blynk
  timer.setInterval(10000, clockDisplay);   //Update blynk lcd time every 10 sec

  timer.setInterval(4500, serialDS18B20);   //Update serial mon data every 4.5 sec
  // timer.setInterval(5500, serialDHT);       //Update serial mon data every 5.5 sec
  timer.setInterval(10000, serialCLOCKOUT);  //Update serial mon data every 6.5 sec

  timer.setInterval(5000, timeLCD);         //Update LCD time every 5 sec
  timer.setInterval(10000, tempsLCD);       //Update LCD temps every 10 sec



}

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

But this isnt really working out for me. It mills got to 60000 and then fermMinutes moves to one but when millis gets to 120000 nothing happens.

Think i see what i have done but unsure how to fix it.

millis is always counting but nothing resets it when it gets past 60sec

Why are you resetting all the variables to 0 every 2s?

Sorry long night. I dont i want them set at the start. Let me move them.

so i moved that section out and now i get a Login timeout.

Now i really am confused.

I have changed all of the timer now to something that works.

I am trying to get the timer to start with a virtual button and stop and reset when i turn it off. If you could point me in the right direction because what i am doing is not working.


#define BLYNK_PRINT Serial
#include "arduino.h"

// #region    Blynk & Esp8266 Setup.
  #include <ESP8266_Lib.h>
  #include <BlynkSimpleShieldEsp8266.h>

// Blynk Project Auth Token from the Blynk App.
  char auth[] = "!!!!!!!!!!";

// WiFi AP Settings.
  char ssid[] = "ubnt-pico";
  char pass[] = "!!!!!!";

// Set ESP8266 Serial object
  #define EspSerial Serial

// ESP8266 baud rate:
  #define ESP8266_BAUD 115200

ESP8266 wifi(&EspSerial);
BlynkTimer timer;
// #endregion

// #region    Fermentation Timer
  char fermTimeBuffer[100];
  int fermSeconds = 0;
  int fermMinutes = 0;
  int fermHours = 0;
  int fermDays = 0;
  // int fermWeeks = 0;
  int HighMillis=0;
  int Rollover=0;
// #endregion

// #region    On Timer Function
// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.

void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V6, millis() / 1000);

}
// #endregion

// #region    Fermentation Timer Function
void fermentTime()
{
  //** Making Note of an expected rollover *****//
  if(millis()>=3000000000){
  HighMillis=1;

  }
  //** Making note of actual rollover **//
  if(millis()<=100000&&HighMillis==1){
  Rollover++;
  HighMillis=0;
  }

  long secsUp = millis()/1000;

  fermSeconds = secsUp%60;

  fermMinutes = (secsUp/60)%60;

  fermHours = (secsUp/(60*60))%24;

  fermDays = (Rollover*50)+(secsUp/(60*60*24));  //First portion takes care of a rollover [around 50 days]


   sprintf(fermTimeBuffer, "Fermentation Timer %d:%d:%d", fermHours, fermMinutes, fermSeconds );
   Serial.println (fermTimeBuffer);
   Blynk.virtualWrite(V15, fermTimeBuffer);

   timer.setInterval(1000, fermentTime);    //Send runtime every sec to blynk
}
// #endregion

// #region    Fermentation Timer Start Functions
BLYNK_WRITE(V30)
{
  fermtimeStart = param.asInt();
  if (fermtimeStart == 1)
  {
    fermentTime();
  }
    else if (fermtimeStart == 0)
    {
      long Day= 0;
      int Hour =  0;
      int Minute= 0;
      int Second= 0;
      int HighMillis= 0;
      int Rollover= 0;
    }
}


void setup()
{
// Debug console &ESP8266 baud rate
  Serial.begin(9600);
  EspSerial.begin(ESP8266_BAUD);
  delay(10);
  Blynk.begin(auth, wifi, ssid, pass, "blynk-cloud.com", 8442);

// Begin synchronizing and starting sensors
  rtc.begin();
  // dht.begin();
  sensors.begin();


// Timers
  timer.setInterval(1000, myTimerEvent);    //Send runtime every sec to blynk
  timer.setTimeout(1500, startLCD);         //LCD Start
  // timer.setInterval(1000, fermentTime);    //Send runtime every sec to blynk
  timer.setInterval(4000, sendDS18B20);     //Send DS18B20 data every 4 sec to blynk
  // timer.setInterval(5000, sendDHT);         //Send DHT data every 5 sec to blynk
  timer.setInterval(10000, clockDisplay);   //Update blynk lcd time every 10 sec

  timer.setInterval(4500, serialDS18B20);   //Update serial mon data every 4.5 sec
  // timer.setInterval(5500, serialDHT);       //Update serial mon data every 5.5 sec
  timer.setInterval(10000, serialCLOCKOUT);  //Update serial mon data every 6.5 sec

  timer.setInterval(5000, timeLCD);         //Update LCD time every 5 sec
  timer.setInterval(10000, tempsLCD);       //Update LCD temps every 10 sec



}

void loop()
{
  Blynk.run();
  timer.run();
  BLYNK_WRITE(30);
}