Hi all,
Does millis() work when is called outside the void loop function? Trying to print a couple of variables at the end of the period it but does not print.
I defined the variable "unsigned long currentTime = 0;" at the beginning.
On the loop, the "currentTime = millis()" and I call a function "NewDay();"
The "NewDay()" uses the millis to calculate the intervals, at the same moment to print the variables but those does not print.
Code below...
Thnks
int Day = 0; // new day will increase the counter
const long DayMillis = 10000; // millis in 1 day. 1,000 millis = 1 sec, 60 secs = 1min, 1hour=60min, 1day=24hours
unsigned long lastDay = 0 ; // will store the millis that lastDay was updated
const float TempMax = 42; // Temperatura Maxima water
float maxTemp = 4; // maxima temperatura of the day, will reset each day
float Temp = 1;
// unsigned long currentTime = millis() , esta variable ira en el loop para resetear maxTemp cuando millis (no se resetea, va contando hasta 49,71 dias) alcance Day valor
unsigned long currentTime = 0;
int LED = D4;
int LEDstate = HIGH;
const long interval = 1000; // Millis at which the LED will blink
unsigned long LEDTime = 0; // variable to for the LED function
unsigned long LEDprevious = 0; // will store last time the LED was updated
void setup() {
Serial.begin(9600);
pinMode(LED, OUTPUT);
digitalWrite(LED, HIGH);
}
void loop() {
unsigned long currentTime = millis();
// unsigned long LEDTime = millis();
NewDay();
// if (Serial.available() > 0) { // Serial monitor Temperature entry
//Temp = Serial.read();
// Serial.print("Temp");
//Serial.println(Temp);
// }
// if (Temp > maxTemp) { // records new maxTemp
// maxTemp = Temp;
// }
// if (maxTemp <= TempMax) {
// actionLED();
// }
}
void NewDay() { // funcion to reset all timers: Day, maxTemp
if (currentTime - lastDay >= DayMillis) {
lastDay = millis(); // lastDay toma el valor de millis actuales
maxTemp = 0; // maxTemp se resetea
Day = ++Day; // contador de dias
Serial.print("last Day...");
Serial.println(lastDay);
Serial.print("maxTemp...");
Serial.println(maxTemp);
Serial.print("Day...");
Serial.println(Day);
Serial.print("Temp...");
Serial.println(Temp);
}
}
/*/
void actionLED() { //still unfinished
if (LEDTime - LEDprevious >= interval) {
LEDprevious = LEDTime;
LEDstate = !LEDstate;
}
}/*/