The millis(), is a blink without delay which controls how often the program checks the temperature. That does not effect it atall, it's the delays within :
if ((int(Thermister(analogRead(0)))) <= HeatAutoOn && heat == false) { //turns heat on
digitalWrite(w, HIGH);
Serial.println("AUTO HEAT ON");
delay(4000);
digitalWrite(g, HIGH);
heat = true;
ac = false;
off = false;
}
I tried to make a blink without delay inside this if statement but I cannot get it to turn on. I labeled the constants and variables for the fan delay. Again, any help is greatly appreciated...
Thanks!
#include <math.h>
//-----------------------------------------------------------------------------------------------------------------------------------
long HeatAutoOn = 18;
long AcAutoOn = 25;
long CheckTemp = 20000;
float TempDiffHeat = HeatAutoOn+1.5;
float TempDiffAc = AcAutoOn-1.5;
//-----------------------------------------------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------------------------------------
unsigned long time;
long previoustime;
int w = 7;
int g = 9;
int y = 8;
boolean heat = false;
boolean ac = false;
boolean off = false;
//-----------------------------------------------------------------------------------------------------------------------------------
//FAN DELAY "BLINK WITHOUT DELAY"----------------------------------------------------------------------------------------------------
unsigned long currentDelay;
long previousDelay;
long fanInterval = 4000;
//----------------------------------------------------------------------------------------------------------------------
void setup(){
pinMode (w, OUTPUT);
pinMode (g, OUTPUT);
pinMode (y, OUTPUT);
Serial.begin(9600);
}
//THERMISTER CALCULATIONS FOR TEMPERATURE CONVERSION---------------------------------------------------------------------------------
double Thermister(int RawADC)
{
double Temp;
Temp = log(((10240000/RawADC) - 10000));
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
Temp = Temp - 273.15; // Convert Kelvin to Celcius
//Temp = (Temp * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
return Temp;
}
//-----------------------------------------------------------------------------------------------------------------------------------
void loop()
{
Serial.print("Degrees C");
Serial.println(int(Thermister(analogRead(0)))); // display C
delay(1000);
currentDelay = millis();
int command = Serial.read();
//TRYING THE "BLINK WITHOUT DELAY" INSIDE THIS JUST TO TEST IF IT WORKS BUT I CANNOT GET IT TO TURN ON---------------------------------
if(command == '1'){
Serial.println("MANUAL HEAT ON");
digitalWrite(w, HIGH);
if ((currentDelay - previousDelay) > fanInterval){
previousDelay = currentDelay;
digitalWrite(g, HIGH);
}
//------------------------------------------------------------------------------------------------------------------------------------
if (command == '2')
{
digitalWrite(w, LOW);
Serial.println("MANUAL HEAT OFF");
delay(4000);
digitalWrite(g, LOW);
}
if(command == '3')
{
digitalWrite(y, HIGH);
digitalWrite(g, HIGH);
Serial.println("MANUAL A/C ON");
}
if (command == '4')
{
digitalWrite(y, LOW);
digitalWrite(g, LOW);
Serial.println("MANUAL A/C OFF");
}
if(command == '5')
{
digitalWrite(g, HIGH);
Serial.println("MANUAL FAN ON");
}
if (command == '6')
{
digitalWrite(g, LOW);
Serial.println("MANUAL FAN OFF");
}
}
if ((int(Thermister(analogRead(0)))) >= TempDiffHeat && (int(Thermister(analogRead(0)))) <= TempDiffAc && off == false){ //turns HVAC off
digitalWrite(w, LOW);
digitalWrite(y, LOW);
off = true;
heat = false;
ac = false;
Serial.println("AUTO HVAC SATISFIED");
digitalWrite(g, LOW);
}
time = millis();
if ((time - previoustime) > CheckTemp ){
previoustime = time;
if ((int(Thermister(analogRead(0)))) <= HeatAutoOn && heat == false) { //turns heat on
digitalWrite(w, HIGH);
Serial.println("AUTO HEAT ON");
delay(4000);
digitalWrite(g, HIGH);
heat = true;
ac = false;
off = false;
}
if ( (int(Thermister(analogRead(0)))) >= AcAutoOn && ac == false) { // turns A/C on
digitalWrite(y, HIGH);
digitalWrite(g, HIGH);
Serial.println("AUTO A/C ON");
heat = false;
ac = true;
off = false;
}
}
}