#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
char auth[] = "xxxxxxxxxxxxxxxxxx";
char ssid[] = "xxxxxxxxxxxxxxxxxx";
char pass[] = "xxxxxxxxxxxxxxxxxx";
BLYNK_WRITE(V1)
{
int pinValue = param.asInt();
if(param.asInt()==1)
{
timer.enable(StartDoTimer ); // Turn StartDoTimer on
Serial.print("V1 IS ON");
// Want infinite loop here, but break it when V1 button is off
}
else
{
Serial.print("V1 IS OFF ");
timer.disable(StartDoTimer ); // Turn StartDoTimer off
}
}
void StartDo (){
//do something
}
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
StartDoTimer = timer.setInterval(1000L, StartDo);
timer.disable(StartDoTimer ); // Turn StartDoTimer off
}
void loop()
{
Blynk.run();
}
Compile error:
sketch_oct05b:15:1: error: ‘timer’ was not declared in this scope
timer.enable(StartDoTimer ); // Turn StartDoTimer on
^
sketch_oct05b:15:14: error: ‘StartDoTimer’ was not declared in this scope
timer.enable(StartDoTimer ); // Turn StartDoTimer on
^
sketch_oct05b:22:1: error: ‘timer’ was not declared in this scope
timer.disable(StartDoTimer ); // Turn StartDoTimer off
^
sketch_oct05b:22:15: error: ‘StartDoTimer’ was not declared in this scope
timer.disable(StartDoTimer ); // Turn StartDoTimer off
^
/tmp/arduino_modified_sketch_600126/sketch_oct05b.ino: In function ‘void setup()’:
sketch_oct05b:35:3: error: ‘StartDoTimer’ was not declared in this scope
StartDoTimer = timer.setInterval(1000L, StartDo);
^
sketch_oct05b:35:18: error: ‘timer’ was not declared in this scope
StartDoTimer = timer.setInterval(1000L, StartDo);
^
exit status 1
‘timer’ was not declared in this scope
I am very sorry for wasting your time, but I am confused
I am now reading the documentation on timers, but for now I can not figure out what exactly causes an error.
This is my fixed code:
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <WidgetRTC.h>
char auth[] = "xxxxxxxxxxxxxxxxxx";
char ssid[] = "xxxxxxxxxxxxxxxxxx";
char pass[] = "xxxxxxxxxxxxxxxxxx";
BlynkTimer timer;
WidgetRTC rtc;
BLYNK_WRITE(V1)
{
int pinValue = param.asInt();
if(param.asInt()==1)
{
timer.enable(StartDoTimer ); // Turn StartDoTimer on
Serial.print("V1 IS ON");
// Want infinite loop here, but break it when V1 button is off
}
else
{
Serial.print("V1 IS OFF ");
timer.disable(StartDoTimer ); // Turn StartDoTimer off
}
}
void StartDo (){
//do something
}
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
StartDoTimer = timer.setInterval(1000L, StartDo);
timer.disable(StartDoTimer ); // Turn StartDoTimer off
}
void loop()
{
Blynk.run();
}
Compile errors:
/tmp/arduino_modified_sketch_566374/sketch_oct05b.ino: In function ‘void BlynkWidgetWrite1(BlynkReq&, const BlynkParam&)’:
sketch_oct05b:19:14: error: ‘StartDoTimer’ was not declared in this scope
timer.enable(StartDoTimer ); // Turn StartDoTimer on
^
sketch_oct05b:26:15: error: ‘StartDoTimer’ was not declared in this scope
timer.disable(StartDoTimer ); // Turn StartDoTimer off
^
/tmp/arduino_modified_sketch_566374/sketch_oct05b.ino: In function ‘void setup()’:
sketch_oct05b:39:3: error: ‘StartDoTimer’ was not declared in this scope
StartDoTimer = timer.setInterval(1000L, StartDo);
^
exit status 1
‘StartDoTimer’ was not declared in this scope