#include <Bounce2.h>
#include <Wire.h> // Comes with Arduino IDE
#include <LiquidCrystal_I2C.h>
#include <OneWire.h>
#include <DallasTemperature.h>
/*-----( Declare objects )-----*/
// set the LCD address to 0x27 for a 20 chars 4 line display
// Set the pins on the I2C chip used for LCD connections:
// addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // ******THIS I2C Address works correctly for my Screen!!!
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
#define tempPin 2
#define relayPin1 7
#define relayPin2 8
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 3; // the number of the pushbutton pin
// Variables will change:
int buttonState; // the current reading from the input pin
int lastButtonState = LOW; // the previous reading from the input pin
// the following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 50; // the debounce time; increase if the output flickers
void setup()
{
Serial.begin(9600);
lcd.begin(20,4);
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("C");
lcd.setCursor(1, 0);
lcd.print((char)223);
lcd.setCursor(0, 4);
lcd.print("Pump");
lcd.setCursor(10, 4);
lcd.print("Burner");
lcd.setCursor(5, 3);
lcd.print("OFF");
lcd.setCursor(17, 3);
lcd.print("OFF");
sensors.begin();
pinMode(buttonPin, INPUT);
}
void loop()
{
temp_read();
int reading = digitalRead(buttonPin);
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading != buttonState) {
buttonState = reading;
if (buttonState == HIGH) {
constant();
}
if (buttonState == LOW) {
off();
}
}
lastButtonState = reading;
}
}
void temp_read()
{
sensors.requestTemperatures();
lcd.setCursor(2, 0);
lcd.print(sensors.getTempCByIndex(0), 0);
}
void constant()
{
if(sensors.getTempCByIndex(0) <= 24.5){
lcd.setCursor(5, 3);
lcd.print("ON ");
lcd.setCursor(17, 3);
lcd.print("ON ");
digitalWrite(relayPin1, LOW);
digitalWrite(relayPin2, LOW);
}
if(sensors.getTempCByIndex(0) >= 25.5){
lcd.setCursor(5, 3);
lcd.print("OFF");
lcd.setCursor(17, 3);
lcd.print("OFF");
digitalWrite(relayPin1, HIGH);
digitalWrite(relayPin2, HIGH);
}
}
void off()
{
lcd.setCursor(5, 3);
lcd.print("OFF");
lcd.setCursor(17, 3);
lcd.print("OFF");
digitalWrite(relayPin1, HIGH);
digitalWrite(relayPin2, HIGH);
}
apologies if im breaking any forum etiquette by just blasting a lot of code here.
If i run the debounce code using it to simply trigger the relays on their own, i can get that to work.
but i want it to run my code "constant" instead of activating a relay and then i guess it has no way of releasing it self from the code if it engages in the "constant" code.
maybe if i set up the system to work if the relays are engaged rather that looking at the button state.....but the problem there is the relays shut them selves off when a certain temperature criterea is met and it may not re engage.
i guess maybe i need to review interrupts? or am i at least on the right road?