Display delay time as timer.

I would like to display the amount of time left on the delay between cycling pins 3 and 4 high and low. I’ve tried a couple print options but none seem to pan out and since i’m less than a novice I thought its time to ask the gurus.

I’ve attached code that works for cycling pins 3 and 4 based on temperature. It also prints the Amb Temp and millis. I don’t really need millis printed. Pin 3 and 4 control two relays for lamps.

Temp_control_on_off_3-2-2020.ino (2.03 KB)

#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

//I2C pins declaration
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

#define ONE_WIRE_BUS 2 //2 is DPin-2 of UNO at which sensor’s output is connected

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire); //sensors is the object created from the class – DallasTemp…
unsigned int dsTemp; //variable to hold Temperature value directly in Celsius
unsigned long presentmillis;

void setup(void)
{
Serial.begin(9600); //initialize Serial Monitor
pinMode(3, OUTPUT); //Lamp control
pinMode(4, OUTPUT); //Lamp control
digitalWrite(3, LOW); //Lamp Off
digitalWrite(4, LOW); //Lamp Off
sensors.begin(); //initialize One-Wire Sensor – DS18B20
lcd.begin(16,2);//Defining 16 columns and 2 rows of lcd display
lcd.backlight();//To Power ON the back light
//lcd.backlight();// To Power OFF the back light

}
void loop(void)
{
showTempOnLCD(); //at 2-sec interval
if (dsTemp < 20)
{
digitalWrite(3, HIGH); //Lamp On
digitalWrite(4, LOW); //Lamp Off
delay(600000);
digitalWrite(3, LOW); //Lamp On
digitalWrite(4, HIGH); //Lamp Off
delay(600000);
presentmillis = millis();

}
if (dsTemp > 20)
{
digitalWrite(3, LOW); //Lamp Off
digitalWrite(4, LOW); //Lamp Off

presentmillis = millis();

}

}
void showTempOnLCD()

{

sensors.requestTemperatures(); // Temp conversion command; waiting here until comversion is done
dsTemp = sensors.getTempCByIndex(0); //read temp data from Sensor #0 and convert to celsius
presentmillis = millis();
lcd.begin (16,2);
lcd.backlight();

lcd.setCursor(0,0);
lcd.print(“Amb Temp:”);
lcd.print(dsTemp);
lcd.write(0xDF);
lcd.print(‘C’);
lcd.setCursor(0,1);
lcd.print (presentmillis);

delay(2000); //sample temperature at 2-sec interval
}

I would like to display the amount of time left on the delay between cycling pins 3 and 4 high and low

Then you cannot use delay() because whilst it happens nothing else will

Take a look at Using millis() for timing. A beginners guide, Several things at the same time and the BlinkWithoutDelay example in the IDE