ir remote > setting different variables with + -

I am currently working on a bigger project and right now i am having a issue with finding out how to use + - to increment or decrement the chosen values.

Right now i have them set only on temperature but i would like to change this so i can choose the variable i want to set before increasing or decreasing the value.

i also want to be able to set some clock values for a timer. turning on and off lights at the set hour and minute.

so what i want to do is: (and need help with)
Hit IR Button

  1. temperature setting (+ - to increment/decrement by 0.5C)
  2. evening time light turn off (+ - to increment/decrement hours and minutes)
  3. morning time light turn on (+ - to increment/decrement hours and minutes)

i also want to be able to override the lights with a buttonpush at any other time but i dont think that should be a problem .

the relevant code i have this faar on this problem is:

for the ir Control

void irsignal()
{
    if (irrecv.decode(&results)) //Result from remote and store in IRecieved
    {          
          IReceived = results.value;
          //Serial.println(results.value);
          
          update = 0;
          switch (IReceived)
          {
            case playpause:
              update = 7;
              lcdDimLights(1);
              break;
            
            case button1:
              openCloseDoor();
              lcdDimLights(0);
              break;
            
            case button2:
              lcdDimLights(0);
              break;
            
            case button3:
              lcdDimLights(0);
              break;
            
            case button4:
              update = 1;
              lcdDimLights(0);
              break;
            
            case button5:
              update = 2;
              lcdDimLights(0);
              break;
            
            case button6:
              update = 3;
              lcdDimLights(0);
              break;
            
            case button7:
              update = 4;
              lcdDimLights(0);
              break;
            
            case button8:
              update = 5;
              lcdDimLights(0);
              break;
            
            case button9:
              update = 6;
              lcdDimLights(0);
              break;
            
            case buttonminus:
              update = 8;
              decreaseTemperature();
              lcdDimLights(0);
              break;
          
            case buttonplus:
              update = 8;
              increaseTemperature();
              lcdDimLights(0);
              break;
            
            case EQ:
              update = 7;
              lcdDimLights(0);
              lcd.setCursor ( 0, 1 );
              lcd.print("Smart SeedHouse     ");
              break;
          }
          irrecv.resume();
  }
}

for the Lights

int eveningHour;
int eveningMinute;
int morningHour;
int morningMinute;

void timerLight()
{
  if (hour() == eveningHour && minute() == eveningMinute)
  {
    digitalWrite(whiteLights, HIGH);
    digitalWrite(plantLights, HIGH);
  }
  else if (hour() == morningHour && minute() == morningMinute)
  {
    digitalWrite(whiteLights, LOW);
    digitalWrite(plantLights, LOW);
  }
}

for the temperature

  float temperatureNow = 0;
  float setTemperature = 25;  // legge til ir setting av temp...
  
void increaseTemperature()
{
  if (setTemperature >= 35) // This is the max limit temperature for the SeedHouse
  {                         // we therefore keep this lot empty as we dont want to increase temp any more
  }
  else if (setTemperature < 35)
  {
    setTemperature = setTemperature + 0.5;
  }
}

void decreaseTemperature()
{
  if (setTemperature > 20) // This is the minimum limit temperature for the SeedHouse
  {                     
    setTemperature = setTemperature - 0.5;
  }
  else if (setTemperature <= 20) // We dont want to decrease temperature more than this
  {
  }
}

and the void loop

void loop()
{
  sensors.requestTemperatures();
  
  // Update for getting live numbers on lcd screen.    
  if (update == 1)
  {
    topSensor();
  }
  else if (update == 2)
  {
    bottomSensor();
  }
  else if (update == 3)
  {
      temperatureProbe1();
  }
  else if (update == 4)
  {
      temperatureProbe2();
  } 
  else if (update == 5)
  {
      temperatureProbe3();
  }
  else if (update == 6)
  {
      temperatureProbe4();
  }  
  else if (update == 7)
  {
      actualTemperature();
  }    
  else if (update == 8)
  {
      setTemperatureShow();
  }     
  else if (update == 9)
  {
      setTemperatureShow();
  }    

  
  
  if (timer > 50)  // Time between DHT22 sensorReads
  {   
           sensorRead();
           timer = 0;
   }
  timer++;
    timerLight();
    heaterCell();
    fanControl();
    earthMoisture();
    irsignal();
    digitalClockDisplay(); 
    lcdDimTimer();   
}

Clock im using

void printDigits(int digits)
{
    lcd.print(':');
    if(digits < 10)
        lcd.print('0');
    lcd.print(digits);
}

void digitalClockDisplay(void)
{
    lcd.home ();
    lcd.print(day());
    lcd.print('.');
    lcd.print(month());
    lcd.print('.');
    lcd.print(year()); 
    lcd.print(' ');
    lcd.print(hour());
    printDigits(minute());
    printDigits(second());
}

Just to be clear, you want to use the same +- buttons to change the temp one time, and later on change the time, and then again the temp at another instant?

I think you would have to use another button to be a sort of shift key. So if you press "that" key, it sets a flag and then in your case buttonminus you have an if/else. The if checks if the flag is set; then one half of the if/else does the temp, the other half does the time.

Something along those lines anyway....

I see

I want to have button1 to set temp, button 2 to set morning timer and button3 to set evening timer.

i guess i see how to do it now except for one thing, on button 2 and 3 i need to set both minutes and hours separately so as you say here i need some kind of shift code.

for example hit button once to set hour then the second to set timer and i guess rotating is the proper way so hit 3 is hours again and so on.

i am not sure however how to write this shifting code.

To double up a button's function I'd do something like this (untested and off the top of my head, beware, ymmv). Let's say you designate buttonX to be your shift button.

//At the top of the sketch, make a flag called say shift:
bool shift = false;
//Then in your IRrecv part add a case:
            
case buttonX:
shift = true;
break;
//Then in the buttonminus case:
case buttonminus:
  if(shift = false) //as before we started with this shift stuff
        {
              update = 8;
              decreaseTemperature();
              lcdDimLights(0);
              break;
          }
else // and here shift must be true cos it can only be false or true
        {
            //do some other stuff as appropriate
            shift=false;  //reset the flag for next time
            break;      
         }

Something like that, anyway....

should be as easy as this then adding a bool for each since i need the false statements when pushing other buttons.. didnt try it yet since code aint finished, got some else if's to go in the + and - section

            case button2:
            if (setMorningHourNow = false)
            {
                setMorningHourNow = true;
                setMorningMinuteNow = false;
            }
            else if (setMorningHourNow = true;)
            {
                setMorningMinuteNow = true;
                setMorningHourNow = false;
            }

ive got this case now that i think it should work but it does not:

for some odd reason i cant increment or decrement hour and minute, when i tested while writing i got to increment and decrement the hour when it was "else if (setEveningHourNow = true)" but that doesnt sit well with the rest of the code.

            case buttonminus:
            if (setTemperatureNow == true)
            {
              update = 8;
              decreaseTemperature();
            }
            else if (setEveningHourNow == true)
            {
              update = 9;
              decrementEveningHour(); 
            }
            else if (setEveningMinuteNow == true)
            {
              update = 9;
              decrementEveningMinute(); 
            }
            
            
              lcdDimLights(0);
              break;
          
            case buttonplus:
            if (setTemperatureNow == true)
            {
              update = 8;
              increaseTemperature();
            }
            else if (setEveningHourNow == true)
            {
              update = 9;
              incrementEveningHour(); 
            }
            else if (setEveningMinuteNow == true)
            {
              update = 9;
              incrementEveningMinute(); 
            }
              lcdDimLights(0);
              break;

i am having trouble getting the shift to work as it should.. thing is that i dont want to be able to change the value after i have hit any other button so i need some kind of int that i can set to 0 or bool to false to get it working.

Thinkerion:
i am having trouble getting the shift to work as it should.. thing is that i dont want to be able to change the value after i have hit any other button so i need some kind of int that i can set to 0 or bool to false to get it working.

?

I have no idea what that means 8)

JimboZA:
?

I have no idea what that means 8)

i have narroved it down to: Toggle 2 states with one button on the ir remote with a last

Btw i see i have some other mistakes in the code so

Seems to be working now except that it locks to Minutes, setEveningHourNow never becomes true. I can now decrement/increment minutes.

Button 2

            case button2:
              showEveningTimer();
              switchEveningHourMinute();
              lcdDimLights(0);
              setTemperatureNow = false;
              break;

Button + and -

            case buttonminus:
            if (setTemperatureNow == true)
            {
              update = 8;
              decreaseTemperature();
            }
            else if (setEveningHourNow == true)
            {
              update = 9;
              decrementEveningHour(); 
            }
            else if (setEveningMinuteNow == true)
            {
              update = 9;
              decrementEveningMinute(); 
            }
            
            
              lcdDimLights(0);
              break;
          
            case buttonplus:
            if (setTemperatureNow == true)
            {
              update = 8;
              increaseTemperature();
            }
            else if (setEveningHourNow == true)
            {
              update = 9;
              incrementEveningHour(); 
            }
            else if (setEveningMinuteNow == true)
            {
              update = 9;
              incrementEveningMinute(); 
            }
              lcdDimLights(0);
              break;

Switch code

void switchEveningHourMinute()
{
   if (setEveningHourNow = false)
  {
      setEveningMinuteNow = false;
      setEveningHourNow = true;
  } 
  else if (setEveningHourNow = true)
  {
      setEveningMinuteNow = true;
      setEveningHourNow = false;
  }
}

OFC dunno why you dont say anything, Syntax errors the code is fine and working :smiley:

Thanks for the help

Cool- glad to help