#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
OneWire oneWire1(10);
DallasTemperature sensors1(&oneWire1);
OneWire oneWire2(11);
DallasTemperature sensors2(&oneWire2);
OneWire oneWire3(12);
DallasTemperature sensors3(&oneWire3);
const int red = 13;
const int green = 14;
unsigned long previousMillisEnableBlink;
unsigned long previousMillisBlink;
unsigned long previousMilliscounter;
bool enableBlink = false;
bool blink = false;
bool enablereading = false;
int counter =0; //one counter with two actions
extern volatile unsigned long timer0_millis;
void setup(void)
{
Serial.begin(9600);
lcd.init();
lcd.backlight();
Serial.println("Measuring 3 sensors' temperatures");
pinMode(red, OUTPUT);
sensors1.begin();
sensors2.begin();
sensors3.begin();
}
void loop(void)
{
digitalWrite(red, LOW);
digitalWrite (green, LOW);
delay(12000); // a delay to absorb any power fluctuations on startup
label:
unsigned long currentMillis = millis();
//millis reset to avoid overflow (to be 20 days in milliseconds)
if(millis() >= 43000)
{noInterrupts ();
timer0_millis=0;
previousMilliscounter=0;
previousMillisBlink=0;
previousMillisEnableBlink=0;
currentMillis=0;
previousMillisBlink=0;
interrupts();}
sensors1.requestTemperatures();
sensors2.requestTemperatures();
sensors3.requestTemperatures();
float R1 = sensors1.getTempCByIndex(0);
float F1 = sensors2.getTempCByIndex(0);
float F2= sensors3.getTempCByIndex(0);
//sensor reading display delay
if( currentMillis - previousMillisBlink >= 2000){
enablereading = !enablereading;
previousMillisBlink = currentMillis;
}
if(enablereading){
if((F2>=0))
{digitalWrite(red, HIGH);}
if((F2<-10 && F2<0))
{digitalWrite(red, HIGH);}
if((F2<-10 ))
{digitalWrite(red, LOW);}
Serial.print("R1=");
Serial.print(R1);
Serial.print(", ");
Serial.print("F1=");
Serial.print(F1);
Serial.print(", ");
Serial.print("F2=");
Serial.print(F2);
Serial.print(", ");
Serial.print("m=");
Serial.print(millis());
Serial.print(", ");
Serial.print("cm=");
Serial.print(currentMillis);
Serial.print(", ");
Serial.print("pmeb=");
Serial.print(previousMillisEnableBlink);
Serial.print(", ");
Serial.print("pmb=");
Serial.print(previousMillisBlink);
Serial.print(", ");
Serial.print("eb=");
Serial.print(enableBlink);
Serial.println();
lcd.setCursor(0,0);
lcd.print("R1 = C");
lcd.setCursor(14,0);
lcd.print((char)223);
lcd.setCursor(8,0);
lcd.print(R1);
//delay(1000);
lcd.setCursor(0,1);
lcd.print("F1 = C");
lcd.setCursor(14,1);
lcd.print((char)223);
lcd.setCursor(8,1);
lcd.print(F1);
//delay(100);
/*
lcd.setCursor(0,0);
lcd.print("F1 = C");
lcd.setCursor(14,0);
lcd.print((char)223);
lcd.setCursor(8,0);
lcd.print(F1); */
}
if(!enablereading) {
lcd.setCursor(0,0);
lcd.print("F2 = C");
lcd.setCursor(14,0);
lcd.print((char)223);
lcd.setCursor(8,0);
lcd.print(F2);
lcd.setCursor(0,1);
lcd.print("R1 = C");
lcd.setCursor(14,1);
lcd.print((char)223);
lcd.setCursor(8,1);
lcd.print(R1);
//delay(1000);
}
//energize green led once every 24 hours each for ??? minutes
//without affecting lcd display scrolling text or
//red led functionality
// below line represents the 24 hour timer during which an action will start & stop once
// & one counter to count two actions on/off
if(currentMillis - previousMilliscounter >= 20000){
counter = 2;
previousMilliscounter= currentMillis;}
// the on time is added here
if ( currentMillis - previousMillisEnableBlink >= 10000 && (counter == 2 || counter == 1) )
{
counter --;
previousMillisEnableBlink = currentMillis;
enableBlink = !enableBlink;
}
if( !enableBlink)
{
digitalWrite( green, LOW);
}
if( enableBlink)
{
digitalWrite( green,HIGH);
}
goto label;
}
Loading
ds18b20
ds18b20
Loading
ds18b20
ds18b20
Loading
ds18b20
ds18b20
F2
F1
R1