LCD countdown const long

Not sure if this makes sense but its driving me nuts.
I want to display the time left until the const long floodTray happens

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
int pump = 5;  // 2 channel relay
int waterValve = 8;
LiquidCrystal_I2C lcd(0x27, 16, 2);  // Set the LCD address to 0x27 for a 16x2 display

const long floodTray = 10000;  // 21600000 = 6 hours
unsigned long previousMillis = 0;

void setup() {
  pinMode(waterValve, OUTPUT);
  pinMode(pump, OUTPUT);
  digitalWrite(waterValve, LOW);
  digitalWrite(pump, LOW);
  lcd.init();
  Serial.begin(9600);
}

void loop() {


  unsigned long currentMillis = millis();

  Serial.println(millis());
  delay(1000);
  lcd.setCursor(0, 0);
  lcd.print("Temp");
  lcd.setCursor(10, 0);


  if (currentMillis - previousMillis >= floodTray) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;
    digitalWrite(waterValve, LOW);
    digitalWrite(pump, HIGH);
    delay(5000);
    digitalWrite(pump, LOW);
    delay(5000);
    digitalWrite(waterValve, HIGH);
    delay(5000);
    digitalWrite(waterValve, LOW);
  }
}

Hi @matt200606 ,

Welcome to the forum..
you mean.. floodTray - (currentMillis-previousMillis)??

should be able to Serial.println the math..
or I misunderstood you??

good luck.. ~q

yes!
thats answer. Thank you

1 Like

You're welcome..

happy coding.. ~q

How do I convert the answer from milli seconds to minutes?

Serial.println(floodTray - (currentMillis - previousMillis));

division, but first make sure you don't divide by 0 too..
else display 0..
if ((floodTray - (currentMillis-previousMillis)) > 0){
divide and conquer..
} else {
display 0
}

~q

ive been looking at this for awhile.

  Serial.println(floodTray - (currentMillis - previousMillis));
  if ((floodTray - (currentMillis - previousMillis)) > 0) {
    /60000
  } else {
    display 0

thats all ive ended up with

sorry..
maybe..

  if ((floodTray - (currentMillis - previousMillis)) > 0) {
  Serial.print("Mins:");  
  Serial.println((floodTray - (currentMillis - previousMillis))/60000);
  } else {
  Serial.println(floodTray - (currentMillis - previousMillis));
}

~q

you bloody champion
thank you

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.