What is egg turn?, you didnt label what that is, but i am assuming something like a microwave rotisary,
What i would instead recommend is scrap the delays, while your running your egg turning routine your ignoring the temperature,
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
unsigned long previousMillis = 0; // last time update
unsigned long interval = 14400000; // interval at which to do something (milliseconds)
int light = 10;
int eggturn = 9;
int THERMISTORPIN = 0;
int samplecount = 500;
float settemp = 110.20f;
void setup ()
{
lcd.begin(16, 2);
pinMode(light, OUTPUT);
pinMode(eggturn, OUTPUT);
pinMode (A0, INPUT);
digitalWrite(light, HIGH);
}
void(* resetFunc) (void) = 0;
void loop ()
{
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval)
{
lcd.noDisplay();
for(int i = 0; i < 200; i++)
{
digitalWrite(eggturn, HIGH);
delay(8);
digitalWrite(eggturn, LOW);
delay(200);
}
currentMillis = millis();
previousMillis = currentMillis;
resetFunc();
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
float sample = 0;
for (int i = 0; i <= samplecount; i++)
{
sample += analogRead(THERMISTORPIN);
delay(1);
}
sample = sample/samplecount;
lcd.setCursor(0, 0);
lcd.print(sample);
lcd.setCursor(0, 1);
lcd.print(settemp);
if(sample <= settemp)
{
digitalWrite(light, LOW);
}
if(sample >= settemp+1.0f)
{
digitalWrite(light, HIGH);
}
}
Instead try something like this, where no task is blocking the temperature conversion, and it only prints once per second to limit how much that slows things down. I made the averaging function into a rolling average, the first value will be noisy, but after that it should be quiet, would have liked to remove the float, but its fine for what its doing.
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
unsigned long previousTurnMillis = 0; // last time the turning sequence began
unsigned long previousStateMillis = 0; // last time the egg turner ran a cycle
unsigned long previousPrintMillis = 0; // last time the egg turner ran a cycle
unsigned long turnInterval = 14400000; // interval at which to begin egg turn (milliseconds)
unsigned long stateIntervalHigh = 8;
unsigned long stateIntervalLow = 200;
unsigned long printInterval = 1000;
byte turnCount = 0; // Number of times it has run a cycle.
byte turnState = 0; // Whether it last set high or low
int light = 10;
int eggturn = 9;
int THERMISTORPIN = 0;
int samplecount = 500;
float settemp = 110.20f;
float sample = analogRead(THERMISTORPIN);
void setup ()
{
lcd.begin(16, 2);
pinMode(light, OUTPUT);
pinMode(eggturn, OUTPUT);
pinMode (A0, INPUT);
//Serial.begin(9600);
digitalWrite(light, HIGH);
}
void(* resetFunc) (void) = 0;
void loop ()
{
unsigned long currentMillis = millis();
if(currentMillis - previousTurnMillis > turnInterval)
{
turnCount = 200;
previousTurnMillis = currentMillis;
}
if(turnCount > 0)
{
if(turnState == 0) // 0 for off, 1 for on
{
if(currentMillis - previousStateMillis > stateIntervalLow)
{
digitalWrite(eggturn,HIGH);
previousStateMillis = currentMillis;
turnState = 1;
}
}
else
{
if(currentMillis - previousStateMillis > stateIntervalHigh)
{
digitalWrite(eggturn,LOW);
previousStateMillis = currentMillis;
turnState = 0;
turnCount--;
}
}
}
if(currentMillis - previousPrintMillis > printInterval)
{
lcd.setCursor(0, 0);
lcd.print(sample);
lcd.setCursor(0, 1);
lcd.print(settemp);
previousPrintMillis = currentMillis;
}
sample = sample * 0.998 + float(analogRead(THERMISTORPIN)) * 0.002;
if(sample <= settemp)
{
digitalWrite(light, LOW);
}
if(sample >= settemp+1.0f)
{
digitalWrite(light, HIGH);
}
}