Switch case and temperature sensor problem

Hi,
My problem is that the temperature readings wont update inside the switch case, temperature readings do update if I cycle trough the cases. I guess the problem is that the program will only go into a case if switchpin is HIGH. I cant find a solution for this problem, could someone push me into right direction.

#include <RunningAverage.h>
#include <OneWire.h>
#include <LiquidCrystal_I2C.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 8

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

RunningAverage myRAIN(10);
RunningAverage myRAOUT(10);
float samples = 0;

float tempC = 0;

const int LEDpin = 10;         // Output pin that the LED is attached to
const int SW1pin = 14;         // Pushbutton switch, raise setpoint1
const int SW2pin = 15;         // Pushbutton switch, lower setpoint1
const int SW3pin = 16;         // Pushbutton switch, raise setpoint2
const int SW4pin = 17;         // Pushbutton switch, lower setpoint2

float insideTemp = 0;          // value read from the insidetemp
float setPointIn = 3;          // Initial value of inside setPoint
float outsideTemp = 0;         // value read from the outsidetemp
float setPointOut = 0.25;      // Initial value of outside setPoint
int SW1state = 0;            // Store state of SW1
int SW2state = 0;            // Store state of SW2
int SW3state = 0;            // Store state of SW3
int SW4state = 0;            // Store state of SW4
int LEDstate = 0;            // Store state of LED
int LCDstate = 0;
const int switchPin = 9;   // momentary switch
int Display = 0;
boolean buttonState = LOW;
boolean lastbuttonState = LOW;
const int tempInterval = 5000;
unsigned long lastTempTime = 0;
unsigned long lastTempTime1 = 0;

//                    addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

//DeviceAddress outsideThermometer = { 0x28, 0xE0, 0x9E, 0x0F, 0x09, 0x00, 0x00, 0x36 };
//DeviceAddress insideThermometer = { 0x28, 0x16, 0xE0, 0x0E, 0x09, 0x00, 0x00, 0xB6 };

DeviceAddress outsideThermometer = { 0x28, 0xFF, 0x33, 0x77, 0x01, 0x17, 0x03, 0x67 }; // Temp 2
DeviceAddress insideThermometer = { 0x28, 0xFF, 0x32, 0x8F, 0x01, 0x17, 0x03, 0xC7 };
void setup()
{
  pinMode(SW1pin, INPUT_PULLUP);  // Enable pull-ups on switches
  pinMode(SW2pin, INPUT_PULLUP);
  pinMode(SW3pin, INPUT_PULLUP);
  pinMode(SW4pin, INPUT_PULLUP);
  pinMode(LEDpin, OUTPUT);        // set LED to be an output pin

  myRAIN.clear(); // explicitly start clean
  myRAOUT.clear(); // explicitly start clean

  lcd.begin(20, 4);
  lcd.clear();
  pinMode(switchPin, INPUT);
  digitalWrite(switchPin, HIGH);      // turn on pullup resistor


  /*-(start serial port to see results )-*/
  delay(10);
  Serial.begin(115200);
  Serial.println("Temperature Program");
  Serial.println("Temperature Sensor: DS18B20");
  delay(10);
  /*-( Start up the DallasTemperature library )-*/
  sensors.begin();

  // set the resolution to 10 bit
  sensors.setResolution(insideThermometer, 10);
  sensors.setResolution(outsideThermometer, 10);
}

void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);

  if (tempC == -127.00)
  {
    lcd.print("Error");
  } else
  {
    lcd.print(tempC);
  }
}

void loop(void)
{


  // Check states of pushbuttons, if pressed change setpoint up or down
  SW1state = digitalRead(SW1pin);
  if (SW1state == 0)
    setPointIn += 0.25;
  SW2state = digitalRead(SW2pin);
  if (SW2state == 0)
    setPointIn -= 0.25;

  // Check states of pushbuttons, if pressed change setpoint up or down
  SW3state = digitalRead(SW3pin);
  if ((SW3state == 0) && (LEDstate = 0))
    setPointOut += 0.25;
  SW4state = digitalRead(SW4pin);
  if (SW4state == 0)
    setPointOut -= 0.25;

  // Average for Inside Temp
  if (millis() - lastTempTime >= tempInterval) {
    float rnIN = sensors.getTempC(insideThermometer);
    myRAIN.addValue(rnIN);
    samples++;
    Serial.print("Running Average IN: ");

    Serial.println(myRAIN.getAverage(), 2);
    Serial.println(myRAIN.getMin(), 2);
    Serial.println(myRAIN.getMax(), 2);

    if (samples == 10)
    {
      samples = 0;
      myRAIN.clear();
    }
    lastTempTime = millis();
  }
  delay(100);

  // Average for Outside Temp
  if (millis() - lastTempTime1 >= tempInterval) {
    float rnOUT = sensors.getTempC(outsideThermometer);
    myRAOUT.addValue(rnOUT);
    samples++;

    Serial.print("Running Average OUT: ");
    Serial.println(myRAOUT.getAverage(), 2);
    Serial.print("Samples");
    Serial.print("\t");
    Serial.println(samples);

    if (samples == 10)
    {
      samples = 0;

      myRAOUT.clear();
    }

    lastTempTime1 = millis();
  }

  delay(100);
  sensors.requestTemperatures();


  // read the sensor value
  insideTemp = myRAIN.getAverage();
  outsideTemp = myRAOUT.getAverage();

#define OFFSET     0.5       // to prevent hysteresis - value to be defined

  // Check sensor value against setpoint, if above light LED
  if
  ((insideTemp > (setPointIn + OFFSET)) && (outsideTemp > (setPointOut + OFFSET)) && (insideTemp > (outsideTemp + OFFSET)))
    LEDstate = 1;
  else if
  (( insideTemp <= setPointIn ) || ( outsideTemp <= setPointOut) || (insideTemp <= outsideTemp))
    LEDstate = 0;
  digitalWrite(LEDpin, LEDstate);

  buttonState = digitalRead(switchPin);
  if (buttonState != lastbuttonState)
  {
    if (buttonState == HIGH)
    {
      delay(100);                        // delay to debounce switch

      Display ++;
      if (Display > 3) {
        lcd.clear();
        Display = 1;
      }

      switch (Display) {

        case 1: {
            lcd.clear(); {
              lcd.setCursor(5, 0);
              lcd.print("Temperatur");
              lcd.setCursor(0, 1);
              lcd.print("In:");
              printTemperature(insideThermometer);
              lcd.print("    ");
              lcd.setCursor(11, 1);
              lcd.print("UT:");
              printTemperature(outsideThermometer);
              lcd.print("    ");
              lcd.setCursor(5, 2);
              lcd.print("Set Point");
              lcd.setCursor(0, 3);
              lcd.print("In:");
              lcd.print(setPointIn);
              lcd.print("    ");
              lcd.setCursor(11, 3);
              lcd.print("UT:");
              lcd.print(setPointOut);
              lcd.print("    ");
              break;
            }

          case 2: {
              lcd.clear();
              lcd.setCursor(5, 0);
              lcd.print("Temperatur");
              lcd.setCursor(0, 1);
              lcd.print("MIN:");
              lcd.setCursor(11, 1);
              lcd.print("MAX:");
              lcd.setCursor(0, 2);
              lcd.print("IN:");
              lcd.print(myRAIN.getMin(), 2);
              lcd.print("    ");
              lcd.setCursor(11, 2);
              lcd.print("IN:");
              lcd.print(myRAIN.getMax(), 2);
              lcd.setCursor(0, 3);
              lcd.print("UT:");
              lcd.print(myRAOUT.getMin(), 2);
              lcd.print("    ");
              lcd.setCursor(11, 3);
              lcd.print("UT:");
              lcd.print(myRAOUT.getMax(), 2);
              break;
            }

          case 3: {
              lcd.clear();
              lcd.setCursor(1, 1);
              lcd.print("Page 3");
              break;
            }
          }

      }

    }
    lastbuttonState = buttonState;
  }
}

Uh, read the temperature before or after the switch..case statement instead of inside one of the cases?

By the way, when you are tempted to suffix (or combine) variable names with numbers, it is time to learn about arrays.

By the way, this comment appears to be wrong:

#define OFFSET     0.5       // to prevent hysteresis - value to be defined

By the way, you sometimes use the old method and sometimes the new method to enable pullups.

By the way, it can be confusing to some people to mix delay(...) and millis().

I managed to do as suggested, moved the temperature reading outside cases. There might be better ways of doing it, but this is what I came up with.

#include <RunningAverage.h>
#include <OneWire.h>
#include <LiquidCrystal_I2C.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 8

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

RunningAverage myRAIN(10);
RunningAverage myRAOUT(10);

float samples = 0;
float tempC = 0;

const int LEDpin = 10;         // Output pin that the LED is attached to
const int SW1pin = 14;         // Pushbutton switch, raise setpoint1
const int SW2pin = 15;         // Pushbutton switch, lower setpoint1
const int SW3pin = 16;         // Pushbutton switch, raise setpoint2
const int SW4pin = 17;         // Pushbutton switch, lower setpoint2

float insideTemp = 0;          // value read from the insidetemp
float setPointIn = 3;          // Initial value of inside setPoint
float outsideTemp = 0;         // value read from the outsidetemp
float setPointOut = 0.25;      // Initial value of outside setPoint
int SW1state = 0;            // Store state of SW1
int SW2state = 0;            // Store state of SW2
int SW3state = 0;            // Store state of SW3
int SW4state = 0;            // Store state of SW4
int LEDstate = 0;            // Store state of LED

const int switchPin = 9;   // momentary switch
int Display = 0;
boolean buttonState = LOW;
boolean lastbuttonState = LOW;

const int tempInterval = 5000;
unsigned long lastTempTime = 0;
unsigned long lastTempTime1 = 0;

//                    addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

//DeviceAddress outsideThermometer = { 0x28, 0xE0, 0x9E, 0x0F, 0x09, 0x00, 0x00, 0x36 };
//DeviceAddress insideThermometer = { 0x28, 0x16, 0xE0, 0x0E, 0x09, 0x00, 0x00, 0xB6 };

DeviceAddress outsideThermometer = { 0x28, 0xFF, 0x33, 0x77, 0x01, 0x17, 0x03, 0x67 }; // Temp 2
DeviceAddress insideThermometer = { 0x28, 0xFF, 0x32, 0x8F, 0x01, 0x17, 0x03, 0xC7 };

void setup()
{
  pinMode(SW1pin, INPUT_PULLUP);  // Enable pull-ups on switches
  pinMode(SW2pin, INPUT_PULLUP);
  pinMode(SW3pin, INPUT_PULLUP);
  pinMode(SW4pin, INPUT_PULLUP);
  pinMode(switchPin, INPUT_PULLUP);
  pinMode(LEDpin, OUTPUT);        // set LED to be an output pin

  myRAIN.clear(); // explicitly start clean
  myRAOUT.clear();

  lcd.begin(20, 4);
  lcd.clear();

  /*-(start serial port to see results )-*/
  delay(10);
  Serial.begin(115200);
  Serial.println("Temperature Program");
  Serial.println("Temperature Sensor: DS18B20");
  delay(10);
  /*-( Start up the DallasTemperature library )-*/
  sensors.begin();

  // set the resolution to 10 bit
  sensors.setResolution(insideThermometer, 10);
  sensors.setResolution(outsideThermometer, 10);
}

void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);

  if (tempC == -127.00)
  {
    lcd.print("Error");
  } else
  {
    lcd.print(tempC);
  }
}

void loop(void)
{
  // Check states of pushbuttons, if pressed change setpoint up or down
  SW1state = digitalRead(SW1pin);
  if (SW1state == 0)
    setPointIn += 0.25;
  SW2state = digitalRead(SW2pin);
  if (SW2state == 0)
    setPointIn -= 0.25;

  // Check states of pushbuttons, if pressed change setpoint up or down
  SW3state = digitalRead(SW3pin);
  if ((SW3state == 0) && (LEDstate = 0))
    setPointOut += 0.25;
  SW4state = digitalRead(SW4pin);
  if (SW4state == 0)
    setPointOut -= 0.25;

  sensors.requestTemperatures();

  // Average for Inside Temp
  if (millis() - lastTempTime >= tempInterval)
  {
    float rnIN = sensors.getTempC(insideThermometer);
    myRAIN.addValue(rnIN);
    samples++;

    Serial.print("Running Average IN: ");
    Serial.println(myRAIN.getAverage(), 2);

    if (samples == 10)
    {
      samples = 0;
      myRAIN.clear();
    }
    lastTempTime = millis();
  }
  delay(20);

  // Average for Outside Temp
  if (millis() - lastTempTime1 >= tempInterval) {
    float rnOUT = sensors.getTempC(outsideThermometer);
    myRAOUT.addValue(rnOUT);
    samples++;

    Serial.print("Running Average OUT: ");
    Serial.println(myRAOUT.getAverage(), 2);

    if (samples == 10)
    {
      samples = 0;
      myRAOUT.clear();
    }

    lastTempTime1 = millis();
  }

  delay(20);


  // read the sensor value
  insideTemp = myRAIN.getAverage();
  outsideTemp = myRAOUT.getAverage();

#define OFFSET     0.5

  // Check sensor value against setpoint
  if
  ((insideTemp > (setPointIn + OFFSET)) && (outsideTemp > (setPointOut + OFFSET)) && (insideTemp > (outsideTemp + OFFSET)))
    LEDstate = 1;
  else if
  (( insideTemp <= setPointIn ) || ( outsideTemp <= setPointOut) || (insideTemp <= outsideTemp))
    LEDstate = 0;
  digitalWrite(LEDpin, LEDstate);


  buttonState = digitalRead(switchPin);
  if (buttonState == HIGH && lastbuttonState == LOW)
  {
    delay(20);                        // delay to debounce switch

    Display ++;
    if (Display > 2)
    {
      lcd.clear();
      Display = 1;
    }

    switch (Display)
    {
      case 1:
        lcd.clear();
        lcd.setCursor(5, 0);
        lcd.print("Temperatur");
        lcd.setCursor(0, 1);
        lcd.print("In:");
        lcd.print("    ");
        lcd.setCursor(11, 1);
        lcd.print("UT:");
        lcd.print("    ");
        lcd.setCursor(5, 2);
        lcd.print("Set Point");
        lcd.setCursor(0, 3);
        lcd.print("In:");
        lcd.print("    ");
        lcd.setCursor(11, 3);
        lcd.print("UT:");
        lcd.print("    ");
        break;

      case 2:
        lcd.clear();
        lcd.setCursor(5, 0);
        lcd.print("Temperatur");
        lcd.setCursor(0, 1);
        lcd.print("MIN:");
        lcd.print("    ");
        lcd.setCursor(11, 1);
        lcd.print("MAX:");
        lcd.print("    ");
        lcd.setCursor(0, 2);
        lcd.print("IN:");
        lcd.print("    ");
        lcd.setCursor(11, 2);
        lcd.print("IN:");
        lcd.print("    ");
        lcd.setCursor(0, 3);
        lcd.print("UT:");
        lcd.print("    ");
        lcd.setCursor(11, 3);
        lcd.print("UT:");
        lcd.print("    ");
        break;

    }

  }
  lastbuttonState = buttonState;

  if (Display == 1)
  {
    lcd.setCursor(4, 1);
    printTemperature(insideThermometer);
    lcd.setCursor(15, 1);
    printTemperature(outsideThermometer);
    lcd.setCursor(4, 3);
    lcd.print(setPointIn);
    lcd.setCursor(15, 3);
    lcd.print(setPointOut);

  }
  if (Display == 2)
  {
    lcd.setCursor(4, 2);
    lcd.print(myRAIN.getMin(), 2);
    lcd.setCursor(15, 2);
    lcd.print(myRAIN.getMax(), 2);
    lcd.setCursor(4, 3);
    lcd.print(myRAOUT.getMin(), 2);
    lcd.setCursor(15, 3);
    lcd.print(myRAOUT.getMax(), 2);
  }

}

Removed the unnecessary comment and fixed the pullup
I also read up on arrays but where in my sketch could/should it be used?

There might be better ways of doing it

There are.

const int SW1pin = 14;         // Pushbutton switch, raise setpoint1
const int SW2pin = 15;         // Pushbutton switch, lower setpoint1
const int SW3pin = 16;         // Pushbutton switch, raise setpoint2
const int SW4pin = 17;         // Pushbutton switch, lower setpoint2

int SW1state = 0;            // Store state of SW1
int SW2state = 0;            // Store state of SW2
int SW3state = 0;            // Store state of SW3
int SW4state = 0;            // Store state of SW4

When you start numbering variables, arrays are almost certainly in order.

unsigned long lastTempTime = 0;
unsigned long lastTempTime1 = 0;

Numbering one of an apparently related set of variables is stupid. Number them all or number none of them.

  } else

NOTHING follows a }.

  // Check states of pushbuttons, if pressed change setpoint up or down
  SW1state = digitalRead(SW1pin);
  if (SW1state == 0)
    setPointIn += 0.25;
  SW2state = digitalRead(SW2pin);
  if (SW2state == 0)
    setPointIn -= 0.25;

Do you REALLY want to keep increasing, or decreasing the setpoint when the switch IS pressed? Or, do you want to increase or decrease ONCE when the switch BECOMES pressed (or becomes released)?

  if ((SW3state == 0) && (LEDstate = 0))

Assigning a value to a variable in an if statement is almost always wrong.

    if (samples == 10)
    {
      samples = 0;
      myRAIN.clear();
    }

It is NOT a running average if you clear the history every time you get the 10th reading.

  buttonState = digitalRead(switchPin);

You get the state of a button (sewn on or thread broken?) by reading the pin that a switch is connected to?

Why, in one place, do you use a switch/case statement, based on Display, while in another place you use two if (should have been one if and one else if) statements?

Thanks for your suggestion, I will try to make the code better. This is my "first" sketch so it will take a while but I'm glad someone points out bad coding that it will not become a habit...

This is how my sketch looks now, still need to learn more about making arrays…

#include <RunningAverage.h>
#include <OneWire.h>
#include <LiquidCrystal_I2C.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 8

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

RunningAverage myRAIN(20);
RunningAverage myRAOUT(20);

float tempC = 0;

const int LEDpin = 10;         // Output pin that the LED is attached to

//pin = 14;   Pushbutton switch, raise setpointIn
//pin = 15;   Pushbutton switch, lower setpointIn
//pin = 16;   Pushbutton switch, raise setpointOut
//pin = 17;   Pushbutton switch, lower setpointOut

const int spPins[] = {14, 15, 16, 17};
const int pinCount = 4;

float insideTemp = 0;          // value read from the insidetemp
float setPointIn = 3;          // Initial value of inside setPoint
float outsideTemp = 0;         // value read from the outsidetemp
float setPointOut = 0.25;      // Initial value of outside setPoint

boolean SW1state = LOW;            // Store state of SW1
boolean SW2state = LOW;            // Store state of SW2
boolean SW3state = LOW;            // Store state of SW3
boolean SW4state = LOW;            // Store state of SW4
boolean lastSW1state = LOW;            // Store laststate of SW1
boolean lastSW2state = LOW;            // Store laststate of SW2
boolean lastSW3state = LOW;            // Store laststate of SW3
boolean lastSW4state = LOW;            // Store laststate of SW4
int LEDstate = 0;            // Store state of LED

const int menuswitchPin = 9;   // momentary switch
int Display = 0;
boolean MenuSwitchState = LOW;
boolean lastMenuSwitchState = LOW;

const int tempInterval = 5000;
unsigned long lastTempTimeIn = 0;
unsigned long lastTempTimeOut = 0;

//                    addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

//DeviceAddress outsideThermometer = { 0x28, 0xE0, 0x9E, 0x0F, 0x09, 0x00, 0x00, 0x36 };
//DeviceAddress insideThermometer = { 0x28, 0x16, 0xE0, 0x0E, 0x09, 0x00, 0x00, 0xB6 };

DeviceAddress outsideThermometer = { 0x28, 0xFF, 0x33, 0x77, 0x01, 0x17, 0x03, 0x67 }; // Temp 2
DeviceAddress insideThermometer = { 0x28, 0xFF, 0x32, 0x8F, 0x01, 0x17, 0x03, 0xC7 };

void setup()
{
  for (int thisPin = 0; thisPin < pinCount; thisPin++) {
    pinMode(spPins[thisPin], INPUT_PULLUP);
  }
  //pinMode(SW1pin, INPUT_PULLUP);  // Set to Input and enable pull-ups on switches
  //pinMode(SW2pin, INPUT_PULLUP);
  //pinMode(SW3pin, INPUT_PULLUP);
  //pinMode(SW4pin, INPUT_PULLUP);



  pinMode(menuswitchPin, INPUT_PULLUP);
  pinMode(LEDpin, OUTPUT);        // set LED to be an output pin

  myRAIN.clear(); // explicitly start clean
  myRAOUT.clear();

  lcd.begin(20, 4);
  lcd.clear();

  /*-(start serial port to see results )-*/
  delay(10);
  Serial.begin(115200);
  Serial.println("Temperature Program");
  Serial.println("Temperature Sensor: DS18B20");
  delay(10);
  /*-( Start up the DallasTemperature library )-*/
  sensors.begin();

  // set the resolution to 10 bit
  sensors.setResolution(insideThermometer, 10);
  sensors.setResolution(outsideThermometer, 10);
}

void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);

  if (tempC == -127.00)
  {
    lcd.print("Error");
  }
  else
  {
    lcd.print(tempC);
  }
}

void loop(void)
{
  // Check states of pushbuttons, if pressed change setpoint up or down
  SW1state = digitalRead(spPins[0]);
  if (lastSW1state == LOW && SW1state == HIGH)
  {
    setPointIn += 0.25;
  }
  lastSW1state = SW1state;

  SW2state = digitalRead(spPins[1]);
  if (lastSW2state == LOW && SW2state == HIGH)
  {
    setPointIn -= 0.25;
  }
  lastSW2state = SW2state;

  // Check states of pushbuttons, if pressed change setpoint up or down
  SW3state = digitalRead(spPins[2]);
  if (lastSW3state == LOW && SW3state == HIGH)
  {
    setPointOut += 0.25;
  }
  lastSW3state = SW3state;

  SW4state = digitalRead(spPins[3]);
  if (lastSW4state == LOW && SW4state == HIGH)
  {
    setPointOut -= 0.25;
  }
  lastSW4state = SW4state;

  sensors.requestTemperatures();

  // Average for Inside Temp
  if (millis() - lastTempTimeIn >= tempInterval)
  {
    float rnIN = sensors.getTempC(insideThermometer);
    myRAIN.addValue(rnIN);
 
    Serial.print("Running Average IN: ");
    Serial.println(myRAIN.getAverage(), 2);

    lastTempTimeIn = millis();
  }
  delay(20);

  // Average for Outside Temp
  if (millis() - lastTempTimeOut >= tempInterval) {
    float rnOUT = sensors.getTempC(outsideThermometer);
    myRAOUT.addValue(rnOUT);
  
    Serial.print("Running Average OUT: ");
    Serial.println(myRAOUT.getAverage(), 2);

     lastTempTimeOut = millis();
  }
  delay(20);

  // read the sensor value
  insideTemp = myRAIN.getAverage();
  outsideTemp = myRAOUT.getAverage();

#define OFFSET     0.5

  // Check sensor value against setpoint
  if
  ((insideTemp > (setPointIn + OFFSET)) && (outsideTemp > (setPointOut + OFFSET)) && (insideTemp > (outsideTemp + OFFSET)))
    LEDstate = 1;
  else if
  (( insideTemp <= setPointIn ) || ( outsideTemp <= setPointOut) || (insideTemp <= outsideTemp))
    LEDstate = 0;
  digitalWrite(LEDpin, LEDstate);


  MenuSwitchState = digitalRead(menuswitchPin);
  if (MenuSwitchState == HIGH && lastMenuSwitchState == LOW)
  {
    delay(20);                        // delay to debounce switch

    Display ++;
    if (Display > 2)
    {
      lcd.clear();
      Display = 1;
    }
  }

  if (Display == 1)
  {
    lcd.setCursor(5, 0);
    lcd.print("Temperatur");
    lcd.setCursor(0, 1);
    lcd.print("In:");
    lcd.print("    ");
    lcd.setCursor(4, 1);
    printTemperature(insideThermometer);
    lcd.setCursor(11, 1);
    lcd.print("UT:");
    lcd.print("    ");
    lcd.setCursor(15, 1);
    printTemperature(outsideThermometer);
    lcd.setCursor(5, 2);
    lcd.print("Setpoint ");
    lcd.setCursor(0, 3);
    lcd.print("In:");
    lcd.print("    ");
    lcd.setCursor(4, 3);
    lcd.print(setPointIn);
    lcd.setCursor(11, 3);
    lcd.print("UT:");
    lcd.print("    ");
    lcd.setCursor(15, 3);
    lcd.print(setPointOut);
  }
  else if (Display == 2)
  {
    lcd.setCursor(5, 0);
    lcd.print("Temperatur");
    lcd.setCursor(0, 1);
    lcd.print("MIN  ");
    lcd.print("    ");
    lcd.setCursor(11, 1);
    lcd.print("MAX ");
    lcd.print("     ");
    lcd.setCursor(0, 2);
    lcd.print("IN:");
    lcd.print("        ");
    lcd.setCursor(4, 2);
    lcd.print(myRAIN.getMin(), 2);
    lcd.setCursor(11, 2);
    lcd.print("IN:");
    lcd.print("    ");
    lcd.setCursor(15, 2);
    lcd.print(myRAIN.getMax(), 2);
    lcd.setCursor(0, 3);
    lcd.print("UT:");
    lcd.print("    ");
    lcd.setCursor(4, 3);
    lcd.print(myRAOUT.getMin(), 2);
    lcd.setCursor(11, 3);
    lcd.print("UT:");
    lcd.print("    ");
    lcd.setCursor(15, 3);
    lcd.print(myRAOUT.getMax(), 2);
  }
  lastMenuSwitchState = MenuSwitchState;
}