I’ve churned through the forum for an answer to what I’m sure is a simple solutions, but I can’t find it. I’ve come close with @JoeS but can’t make it work .
Using WidgetRTC and the default code provided by @vshymanskyy how do you convert military time into a standard 12hr format with the AM, PM displayed??? Do I use hour12() inplace of hour() ? If so, how do you get the AM PM, isAM() or isPM()? Are these just True/False statements?
THANKS IN ADVANCE !
Cheers,
#include "BlynkSimpleEsp8266.h"
#include "ESP8266WiFi.h"
#include "ArduinoOTA.h"
//#include "DNSServer.h"
#include "SimpleTimer.h"
#include "Wire.h"
#include "WidgetRTC.h"
#include "WidgetLCD.h"
#include "WidgetLED.h"
//#include "LM75A.h" // for a temperature sensor
#define BLYNK_PRINT Serial
#define SERIAL_EN
#ifdef SERIAL_EN
#define SERIAL_BAUD 115200
#define DEBUG(input) {Serial.print(input);}
#define DEBUGln(input) {Serial.println(input);}
#define SERIALFLUSH() {Serial.flush();}
#else
#define DEBUG(input);
#define DEBUGln(input);
#define SERIALFLUSH();
#endif
char auth[] = "##################";
char ssid[] = "FBI Surveillance Van";
char pass[] = "2022782000";
char Date [16];
char Time [16];
SimpleTimer timer;
WidgetRTC rtc;
void clockDisplay()
{
sprintf(Time, "%02d:%02d:%02d", hour(), minute(), second());
sprintf(Date, "%02d/%02d/%04d", month(), day(), year());
Serial.print("\tCurrent time: ");
Serial.print(Time);
Serial.print("\t");
Serial.print(Date);
Serial.println();
Blynk.virtualWrite(V1, Time);
Blynk.virtualWrite(V2, Date);
}
void setup() {
#ifdef SERIAL_EN
Serial.begin(SERIAL_BAUD);
#endif
WiFi.mode(WIFI_STA);
Blynk.begin(auth, ssid, pass);
while (Blynk.connect() == false);
delay(4000);
yield();
rtc.begin();
delay(300);
yield();
setSyncInterval(300000); // Time Sync Every 5 min
ArduinoOTA.setHostname("NewBuild"); // OPTIONAL
delay(2000);
yield();
Serial.println("\t\tSet OTA Hostname New_Build ");
Serial.println("");
Serial.println("");
delay(10);
yield();
Serial.println(WiFi.status());
Serial.println("");
Serial.println("");
Serial.print("\tAssigned Local IP:\t\t");
Serial.println(WiFi.localIP());
if (WiFi.status() == WL_CONNECTED) {
Serial.println("\tWiFi C O N N E C T E D !!!.");
Serial.println("");
Serial.println("");
Serial.println("\tWifi Started");
}
ArduinoOTA.begin();
delay(300);
yield();
Serial.println("\t\tOTA Began");
Serial.println("");
timer.setInterval(15000L, clockDisplay);
//Serial.print("\t Blynk Ver: ");
Serial.println(F("\tBlynk v" BLYNK_VERSION ": Device started"));
Serial.println("");
}
void loop() {
Blynk.run();
timer.run();
ArduinoOTA.handle();
}
Ya, @Gunner, I get the math! Thanks for pointing it out. At the end of the day this whole forum could be replaced with Google searches. Just to be fair I followed your link provided. It was a useless link. If you don’t know the answer to a simple question to help out other Blinkers on a topic under the heading "Need Help With My Project", maybe you should just pass. Again… maybe someday we’ll all know everything about Blynk, C++. Until that day comes, I’d still appreciate constructive advice.
You are closer to the mark then you think on that one This is a Blynk forum, but many of the questions ARE NOT Blynk related… that does muddy up the waters for those who have Blynk specific issues.
@Jamin, I’ll go back and review those pages again. I’ve looked through them at length prior to this post and didn’t understand the integration into the code.
Good example @Jamin Thank Heavens for bad beach days (once in awhile ;))
Syntax beats my hacked math method… I think it messes up on 0:00 hours… but then I wasn’t really doing any research as I prefer the military time (keeps me thinking) and I didn’t feel like being a code monkey today
void clockDisplay()
{
int HOUR = hour();
if ( HOUR > 12 ) {
HOUR = HOUR - 12;
String currentTime = String(HOUR) + ":" + minute() + ":" + second() + " PM";
Blynk.virtualWrite(V12, currentTime); // Send PM time to the App
} else {
String currentTime = String(hour()) + ":" + minute() + ":" + second() + " AM"; ;
Blynk.virtualWrite(V12, currentTime); // Send AM time to the App
}
String currentDate = String(month()) + " " + day() + " " + year();
Blynk.virtualWrite(V13, currentDate); // Send date to the App
}
You are speaking to a total amateur coder here as well… and while I do appreciate examples to glean from, I still rely HEAVILY on Google and Arduino - Home and try to only ask Blynk specific questions now (except when I am begging for Linux help… then I whimper like a baby ;P)
All is well… If I didn’t really care to help, even in a “Tough Love” format (as one other put it), I would NEVER answer anyone’s postings