Hello guys
I have few questions about how work the Time Input Widget and Numeric Input Widget.
First, the Time Input Widget.
Basically, how can I save the state of the Time Input (For example, selecting in the UI 15:30) and then put that state in a value (Something like: time = Time Input State (15:30 in this case);
Second, the Numeric Input Widget.
I want to do something like the Time Input, but in this case, how can I save the state of the Numeric Input (For example: selecting in the UI the number 10) and also put that state in a value (Something like: number = Numeric Input State (10, in this case;).
Thank you in advance
Read this…
This one, while still undocumented, is a basic value parameter command…
EG. Input widget set to V0
BLYNK_WRITE(V0)
{
int value = param.asInt(); // Get value as integer... or...
// float value = param.asFloat(); // Get value as float, if using decimals.
Serial.print(" The value is: ");
Serial.println(value);
}
If you want to use the variable “value” outside of this function, then set it up as a global variable…
Note: The widget itself has multiple input options, an incremental or decremental value step (the value adjustable in the settings) or a direct value input.
1 Like
I tried to use this code:
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <WidgetRTC.h>
BlynkTimer timer;
char auth[] = "xxxxx";
char ssid[] = "xxxxx";
char pass[] = "xxxxx";
char currentTime[9];
char startTime[9];
char stopTime[9];
int SThour;
int STmin;
int STsec;
int SPhour;
int SPmin;
int SPsec;
WidgetRTC rtc; // Set RTC widget.
void setup()
{
pinMode(2, OUTPUT); // Built-in LED
digitalWrite(2, HIGH); // Turn OFF built-in LED
Serial.begin(115200); // Debug console
Blynk.begin(auth, ssid, pass);
rtc.begin();
setSyncInterval(360);
timer.setInterval(30000L, TimeCheck); // Update Time Check every 30 seconds
}
BLYNK_CONNECTED() {
Blynk.syncVirtual(V1); // Synchronize Time Input Widget when connected
TimeCheck(); // Initial Time Check
}
void loop()
{
Blynk.run();
timer.run();
}
BLYNK_WRITE(V1) { // Called whenever setting Time Input Widget
TimeInputParam t(param);
SThour = t.getStartHour();
STmin = t.getStartMinute();
STsec = t.getStartSecond();
SPhour = t.getStopHour();
SPmin = t.getStopMinute();
SPsec = t.getStopSecond();
}
void TimeCheck() { // call with timer every 30 seconds or so
// Get RTC time
sprintf(currentTime, "%02d:%02d:%02d", hour(), minute(), second());
Serial.print("Current Time: ");
Serial.println(currentTime);
// Get Time Input Widget time
sprintf(startTime, "%02d:%02d:%02d", SThour, STmin, STsec);
Serial.print("Start Time: ");
Serial.println(startTime);
sprintf(startTime, "%02d:%02d:%02d", SPhour, SPmin, SPsec);
Serial.print("Stop Time: ");
Serial.println(startTime);
if (hour() == SThour) {
if (minute() == STmin) {
Serial.println("Doing something now");
digitalWrite(2, LOW); // Turn ON built-in LED
} else if (minute() < STmin) {
Serial.println("Will do something");
} else if (minute() > STmin) {
Serial.println("Did something");
} else {
Serial.println("Clueless");
}
}
if (hour() == SPhour) {
if (minute() == SPmin) {
Serial.println("Stopping something now");
digitalWrite(2, HIGH); // Turn OFF built-in LED
} else if (minute() < SPmin) {
Serial.println("Will stop something");
} else if (minute() > SPmin) {
Serial.println("Stopped something");
} else {
Serial.println("Clueless");
}
}
Serial.println("----------");
}
But the Serial Monitor show me this:
Why this happen?
Of course the Time Input Widget is in V1 in my Blynk App, and I already add the RTC Widget
In your code you have set Serial to 115200 baud but in your serial monitor you have it set to 9600
Serial.begin(115200); // Debug console
1 Like
Oh, I didn’t notice haha. Thank you both, now it works!!
1 Like