Functions not passing return value to my control void loop


I can’t get the ‘return buttonPushCounter’ from my ‘int temp_control()’ function to go into my ‘void loop()’ function. I’m not sure if theres something wrong with my ‘int temp_control()’ function, like where I’ve got the lines of code ‘UplastButtonState = UpbuttonState;’ might be in the wrong {} things. If this all works it should print the temp_control number which is the number from the up & down button presses, and control the relays.

The ‘float TempsensorRead()’ works as it’s value is passed to the void loop function and then printed on the serial.

Any help would be great!

Cheers Simon

Heater_Controller_jan07.ino (4.52 KB)

Please post you code here to avoid the need to download it. Please use code tags when you post it.

    UplastButtonState = UpbuttonState;//NOT SURE IF I"VE PUT THIS IN THE LINE CORRECT {}
    DownlastButtonState = DownbuttonState;//NOT SURE IF I"VE PUT THIS LINE IN THE CORRECT {}

These lines are in the wrong place as you suggested. You are only saving the previous states after they have changed whereas you need to save them before you read the inputs again. Move those lines to immediately before you read the new values.

float TempsensorRead() {
  //subtract the last reading
  total = total - readings[readIndex];

The comment is incorrect - you're subtracting the oldest reading in the buffer, not the last one.