DS18B20 Menu help

Hi all,

Since my controller project for my aquarium has progressed i’d like to add a menu system to include setting a high/low temp settings for my heater and heatsink fan.I have a basic menu system already setup but would like to know how I would go about setting up a user settable input instead of using a pre-programmed code like: (code would not let me change the color)

// DS18B20 display
sensors.requestTemperatures(); // Send the command to get temperatures
delay(250);

lcd.setCursor(13, 1);

float temp1=0, temp2=0;

//lcd.print(“Led Temp:”);
temp1= sensors.getTempFByIndex(1);
lcd.print(sensors.getTempFByIndex(1));
lcd.print((char)223);
lcd.print(“F”);

lcd.setCursor(2, 1);
//lcd.print("Tank Temp: ");
temp2= sensors.getTempFByIndex(0);
lcd.print(sensors.getTempFByIndex(0));
lcd.print((char)223);
lcd.print(“F”);

if ( (temp1) > 98)
{
digitalWrite(fan, HIGH);
digitalWrite(alarm, HIGH);
delay(1000);
digitalWrite(alarm, LOW);
}
else if ( (temp1) < 92)
{
digitalWrite(fan, LOW);
}

if ( (temp2) < 78 )
{
digitalWrite(heater, HIGH);
digitalWrite(alarm, HIGH);
delay(1000);
digitalWrite(alarm, LOW);
}
else if ( (temp2) > 82 )
{
digitalWrite(heater, LOW);
}
// lcd.print(sensors.getTempCByIndex(0));
// lcd.print((char)223);
// lcd.print(“C”);

How would I go about being able to change the RED labeled values in a menu?

You could make them variables, and then the menu code would just have to change the variables.

So for like the Set temp that i have of let say 79 I should change it to something like & [f]…to where is the user definable value for the heater and the [f] for the fan or since there are two different user definable values for on/off then would i need something like # for on variable and ## for the off variable?

Am just looking around and found this for a touchscreen glcd though done up by Vasco for his aquarium controller but he’s MIA.Am hoping I got all the parts needed for that part of creating a user definable setting for the temps…am wondering if it’ll work for a regular 20x4 with modifications to the code for use with the lcd/keypad backpack…

// Water sensor plugged into pin 2, heatsink sensor plugged into pin 3
#define ONE_WIRE_BUS_W 2      
#define ONE_WIRE_BUS_H 3
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWireW(ONE_WIRE_BUS_W);
OneWire oneWireH(ONE_WIRE_BUS_H);
// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensorW(&oneWireW);       //water sensor
DallasTemperature sensorH(&oneWireH);      //heatsink sensor


const int tempHeatPin = 9;
const int tempCoolPin = 10;
const int tempAlarmPin = 11;    //Buzzer
const int fan1PWMpin = 5;       //PWM for heatsink fan
const int fan2PWMpin = 6;       //PWM for heatsink fan

float tempC =0;              // water temperature values
float setTempC = 0;
float offTempC = 0;
float alarmTempC = 0;
boolean tempCflag=0;        //1 if cooling on
boolean tempHflag=0;        //1 if heating on
boolean tempAflag=0;        //1 if alarm on
const int HtempMin = 30;    //temp when heatsink fan starts
const int HtempMax = 40;    //temp when heatsink fan is 100% 
float tempH = 0;              //heatsink temperature
float temp2beS;               //temporary values
float temp2beO;
float temp2beA;

struct config_t
{
    int tempset;
    int tempoff;
    int tempalarm;
} tempSettings;

//---------------------------------------------Temperature Settings------------------
void tempScreen(boolean refreshAll=false)
{
  if (refreshAll)
    {
     if (setTempF==0) {
       setTempF = tempF;  }                  //change to current temp.
     temp2beS = setTempF;
     temp2beO = offTempF;
     temp2beA = alarmTempF;
     
     printHeader("Temperature control settings");

    }
}

//---------------------------------------------------------------------------------------------
void checkTempF()
{ 
 sensorW.requestTemperatures();
 tempC = (sensorW.getTempFByIndex(0));      //read water temperature
 sensorH.requestTemperatures();
 tempH = (sensorH.getTempFByIndex(0));      //read heatsink temperature

 
/* if (tempC<0) tempC=0;                      //if sensor not connected reading is -127 deg
  else if (tempC>99) tempC=99;
 if (tempH<0) tempH=0;
  else if (tempH>99) tempH=99; */
 
  if (tempC<(setTempC+offTempC+alarmTempC) && tempC>(setTempC-offTempC-alarmTempC)) {
    tempAflag = false;
    digitalWrite(tempAlarmPin, LOW);                                   //turn off alarm
    }
  if (tempC<(setTempC+offTempC) && tempC>(setTempC-offTempC))          //turn off cooler/heater
      {
       tempCflag=false;
       tempHflag=false;
       digitalWrite(tempHeatPin, LOW);
       digitalWrite(tempCoolPin, LOW);   
       }
  if (offTempC>0)
    {
    if (tempC >=(setTempC+offTempC))                           //turn on cooler
     {
      tempCflag=true;
      digitalWrite(tempCoolPin, HIGH);
      }
    if (tempC<=(setTempC-offTempC))                          //turn an heater
     {
      tempHflag=true;
      digitalWrite(tempHeatPin, HIGH);
      }
    }
  if (alarmTempC>0)                        //turn on alarm
     {
     if ((tempC>=(setTempC+offTempC+alarmTempC)) || (tempC<=(setTempC-offTempC-alarmTempC)))
      {
      tempAflag=true;
      digitalWrite(tempAlarmPin, HIGH);
      }
     }
   
  int tempval = int(tempH*10);
  int fanSpeed = map(tempval, (HtempMin*10), (HtempMax*10), 170, 255);       //---------heatsink fan control
  if (fanSpeed<=0) 
     fanSpeed = 0;
  if (fanSpeed>255)
     fanSpeed=255;
  if (fanSpeed>=190)
     digitalWrite(fanTranzPin, HIGH);
  if (fanSpeed<=171)
     digitalWrite(fanTranzPin, LOW);
  analogWrite(fan1PWMpin, fanSpeed);
  analogWrite(fan2PWMpin, fanSpeed);
 // Serial.println(fanSpeed);
}

//---------------------------------------------------------------------------------------------
void SaveTempToEEPROM()
{
 tempSettings.tempset = int(setTempC*10);
 tempSettings.tempoff = int(offTempC*10);
 tempSettings.tempalarm = int(alarmTempC*10);
 EEPROM_writeAnything(194, tempSettings);
}

void ReadFromEEPROM()
{
  int k = EEPROM.read(0);
  char tempString[3];
  EEPROM_readAnything(194, tempSettings);  
  setTempC = tempSettings.tempset;
  setTempC /=10;
  offTempC = tempSettings.tempoff;
  offTempC /=10;
  alarmTempC = tempSettings.tempalarm;
  alarmTempC /= 10;

}

/----------------------------------------------------------------------------------------------
    case 4:             //---------------------------------------temperature settings----------------------
       if ((x>=prOK[0]) && (x<=prOK[2]) && (y>=prOK[1]) && (y<=prOK[3]))       //press ok
        {
        waitForIt(prOK[0], prOK[1], prOK[2], prOK[3]);
        setTempC = temp2beS;
        offTempC = temp2beO;
        alarmTempC = temp2beA;
        dispScreen=0;
        SaveTempToEEPROM();
        clearScreen();
        mainScreen(true);
        } else
          {
           if (() && ())                         //first column
             {
              if (() && ())                      //press temp minus
                {
                 waitForIt();
                 temp2beS -= 0.1;
                 if (temp2beS<10) {
                    temp2beS = 10; }
                 tempScreen();
                 }
              if (() && ())                       //press offset minus
                {
                 waitForIt();
                 temp2beO -= 0.1;
                 if (temp2beO <= 0.1) {
                    temp2beO = 0.0; }
                 tempScreen();
                 }          
              if (() && ())                        //press alarm minus
                {
                 waitForIt();
                 temp2beA -= 0.1;
                 if (temp2beA < 0.1) {
                    temp2beA = 0.0;  }
                 tempScreen();
                 }
             }
           if (() && ())                             //second column
              {
               if (() && ())                      //press temp plus
                 {
                  waitForIt();
                  temp2beS += 0.1;
                  if (temp2beS >= 40) {
                     temp2beS = 40; }
                  tempScreen();
                  }
               if (() && ())                           //press offset plus
                 {
                  waitForIt();
                  temp2beO += 0.1;
                  if (temp2beO >= 10) {
                     temp2beO = 9.9; }
                  tempScreen();
                  }
              if (() && ())                           //press alarm plus
                {
                 waitForIt();
                 temp2beA += 0.1;
                 if (temp2beA >= 10) {
                    temp2beA = 9.9;  }
                 tempScreen();
                 }
              }
          }
         break;
//------------------------setup------------------------------
void setup()
{
  Serial.begin(9600);

  pinMode(tempHeatPin, OUTPUT);
  pinMode(tempCoolPin, OUTPUT);
  pinMode(tempAlarmPin, OUTPUT);
  pinMode(fan1PWMpin, OUTPUT);
  pinMode(fan2PWMpin, OUTPUT);
  pinMode(fanTranzPin, OUTPUT);
   
  sensorW.begin();     //start up temperature library
  sensorH.begin();     //start up temperature library
  
  ReadFromEEPROM();

}