having problems with my project, cant get timers to work. i had this bit of code mostly working while using blynk timer. trying to move away from using blynk. may have been causing my Particle.publish
to be blocked… but system timers wont work. no sure where ive gone wrong. any pointer would be great! also do i need SYSTEM_THREAD(ENABLED);
?
SYSTEM_MODE(SEMI_AUTOMATIC);
SYSTEM_THREAD(ENABLED);
char TimeBuffer[100];
int SEC = 0;
int MIN = 0;
int HRS = 0;
int Button;
int LED = D7;
int Switch1 = D1;
int Switch2 = D2;
boolean ButtonState = 0;
boolean Ignition = 0;
boolean Sent = 1;
int val1;
int val2;
Timer CountDown(1000, Count);
Timer Connect(30000, Disconnect);
void Count() {
++SEC;
if(SEC == 60)
{
++MIN;
SEC = 0;
}
if(MIN == 59 && SEC == 59)
{
++HRS;
SEC = 0;
MIN = 0;
}
sprintf(TimeBuffer, "Timer %d:%d:%d", HRS, MIN, SEC );
digitalWrite(LED, HIGH);
delay(100);
digitalWrite(LED, LOW);
}
void setup() {
delay(5000);
pinMode(Switch1, INPUT);
pinMode(Switch2, INPUT);
pinMode(LED, OUTPUT);
digitalWrite(LED, LOW);
}
void Publish(){
Connect.start();
Particle.connect();
waitUntil(Particle.connected);
Connect.stop();
Particle.process();
Particle.publish("Current Run Time", TimeBuffer, PRIVATE, WITH_ACK);
Sent = 1;
Disconnect();
}
void Disconnect()
{
delay(1000);
Particle.disconnect();
delay(1000);
WiFi.off();
}
void loop() {
val1 = digitalRead(Switch1);
if(val1 == LOW)
{
Particle.connect();
}
val2 = digitalRead(Switch2);
if(val2 == LOW)
{
CountDown.start();
Ignition = 1;
Sent = 0;
}
else
{
CountDown.stop();
Ignition = 0;
}
if((Time.hour() >= 18) && (Ignition == 0) && (Sent == 0))
{
Publish();
}
}