Good night.
I wrote a code with the following characteristics:
- if condition 1 is satisfied
- counts a preset time interval 1
- if condition 2 is satisfied
- counts a preset time interval 2
- if condition 3 is satisfied
- counts a preset time interval 3 and executes a routine
Note: the time until the execution of this routine, if it satisfies the above 3 conditions, must be the sum of time 1 + time 2 + time 3.
void loop() {
if (condition1){
unsigned long previous_millis = millis();
while(millis() - previous_millis <= interval1);
if (condition2){
unsigned long previous_millis = millis();
while(millis() - previous_millis <= interval2);
if (condition3){
unsigned long previous_millis = millis();
while(millis() - previous_millis <= interval3);
if (ledState == LOW) {
ledState = HIGH;
} else {
ledState = LOW;
}
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("tempo: ");
unsigned long tempo = millis();
lcd.println(tempo);
digitalWrite(saida_1, ledState);
}
}
}
}
For the case of interval1 = interval2 = interval3 = 2000, the delay interval was 6000 (it’s right).
I’m using the millis () function along with while cycles. Does this lock the processor?
I wish it would not crash that way. I wanted it to be like the blink without delay example.
Thanks any help.