project heating controls, not grasping the coding concept

Hi all,
i am currently working on heating controls with 3 buttons, i am totally caught with the blasted debounce concept. I have completed code with other projects but have never taken on anything of this size.

i am above novice in vb.net,sql,vba and had a module of a c++ course done a few years back.

i'm doing my best to get this to work but it has me beat, i need to get it to work once or at the very least explained to me so i can move forward.

I AM NOT ASKING FOR ANYONE TO DO MY CODING.

my problem is is i touch the debounce and i want a piece of code to run....nada, nothing happens.

maybe i have it wrong. Can someone have a look and advise?

many thanks in advance.

code @ http://codepaste.net/qpgohi

Press Send too soon?

Should be fixed now :o

unreal_event_horizon:
code @ http://codepaste.net/qpgohi

Post it here in the thread and you'll have a much better chance of someone seeing it.

#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?

Can you able to come up with a simple code, so that when you press a button, activate a relay. Releasing the button will switch off the relay.

Later you can add other codes to your requirement.

sarouje:
Can you able to come up with a simple code, so that when you press a button, activate a relay. Releasing the button will switch off the relay.

Later you can add other codes to your requirement.

yes i can, but when i try to add more code based on a button press it just does not work, very frustrating.

I'll keep at it and report back! 8)

#include <Bounce2.h>

This is a useful library, and the latest versions contain several additional features, like state change detection.

You include the library, but never use its functions.

If you are having issues with button debounce, you might do well to use the library.