why 1000? so for all the negative numbers will be 1000? what would happen in the second, third…loop (all will be negative, so all will be 1000)? so it would not reach the interval time?
I want to run my code for 12 months, will it work?
#define publish_cycle 30000
unsigned long lastPublish = 0;
int led = D7;
double reading = 0.0;
double mvolts = 0.0;
double tempC = 0.0;
double tempF = 0.0;
boolean flag = false;
double readingl=0.0;
void setup() {
pinMode(led,OUTPUT);
Particle.keepAlive(120);
Particle.function("led", ledStatus);
}
void loop() {
unsigned long now = millis();
reading = analogRead(A0);
mvolts = (reading * 3300.0)/4095.0;
mvolts = mvolts -500.0;
tempC = mvolts/10.0;
tempF = (tempC*1.8) + 32.0;
readingl = analogRead(A1);
//to IFTTT
if ( tempC > 26.0 && flag == false){
Particle.publish("toohot");
flag = true;
}
if (tempC < 24.0 && flag == true){
Particle.publish("tempnormal");
flag = false;
}
if ((unsigned long)(now - lastPublish) > publish_cycle) {
//to LOSANT
Particle.publish("temp-reading", String(tempC), PRIVATE) ;
Particle.publish("light-intensity",String(readingl), PRIVATE) ;
delay(500);
//to ThingSpeak
Particle.publish("temperature", "{ \"1\": \"" + String(tempC) + "\"," + "\"2\": \"" + String(readingl) + "\"}", PRIVATE);
lastPublish=now;
}
}
int ledStatus(String command){
if(command.equalsIgnoreCase("on")){
digitalWrite(led,HIGH);
return 1;
}
else if (command.equalsIgnoreCase("off")){
digitalWrite(led,LOW);
return 0;
}
else{
return -1;
}
}