Problems with displaying different sensor values on lcd with ir sensor.

PaulS:
Suppose you have a bicycle and a circular track. Each time you go around the track, some will hold up a board with a number on it. If the number is 1, you need to stop and do the hokey pokey. If the number if 2, you stop and chug a beer. If the number is 3, you race around the track like the hounds of hell are after you.

Can you see that you need to look at the board on every pass around the track, NOT what was written on the board the first time around?

Can you see that writing something on the board is COMPLETELY independent of your reading what is on the board?

You need to do three things on EVERY pass through loop():

  1. See if there is IR data to read. If there is, read it.
  2. Collect the data to display, regardless of what data needs to be displayed
  3. Display the required data.

You are currently ONLY displaying data when what to display changes.

You have the right idea with svjetlost() (except for the noDisplay()/display() stuff and the delay() crap).

But, you only call the function when the remote is used to change what should be displayed.

byte whatToDisplay = 0;

void loop()
{
  determineWhatToDisplay();
  collectData();
  displayWhatNeedsToBeDisplayed();
}

void determineWhatToDisplay()
{
   if (receiver.decode(&results))
   { // Down here where it belongs
      if (results.value ==  0xFF30CF )
      {
         whatToDisplay = 1;
      }
      else if(results.value == 0xFF18E7)
      {
         whatToDisplay = 2;
      }
      // More else if statements here
   }
}

void displayWhatNeedsToBeDisplayed()
{
  switch(whatToDisplay)
  {
     case 1:
        someFunction();
        break;
     case 2:
         svjetlost();
        break;
  }
}




Now, YOU fill in the rest of the else if statement, the rest of the cases, and write the collectData() function.

I feel soo stupid right now, This is what I did and it isn't displaying anything. Do I have to make a function for every sensor. And in the last void in the case function, I see that there it calls for svjetlost(), so is svjetlost also a separate function? And if I put all the readings in collectData, how do I call it in the second void? Sorry to bother you again but I have to do this and I don't have the time to experiment on it so much.

byte whatToDisplay = 0;
#include <LiquidCrystal.h>
#include <IRremote.h>
#include <IRremoteInt.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int RECV_PIN = 10;
IRrecv receiver(RECV_PIN);
decode_results results;
int sPin = A0;
int svjetlo;

void setup(){
  
    Serial.begin(9600);
  lcd.begin(16, 2);

  receiver.enableIRIn();
  
  }

void loop()
{
  void determineWhatToDisplay();
  void collectData();
  void displayWhatNeedsToBeDisplayed();
}
void svjetlost()
{
  svjetlo = analogRead(sPin);
  
  
  
  }
void determineWhatToDisplay()
{
    if (receiver.decode(&results))
    { // Down here where it belongs
       if (results.value ==  0xFF30CF )
       {
         whatToDisplay = 1;
           svjetlo = analogRead(sPin);
         lcd.setCursor(0,1);
         lcd.print("Svjetlost je:");
         lcd.print(svjetlo);
       }
       else if(results.value == 0xFF18E7)
       {
          whatToDisplay = 2;
       }
      
    }
}

void displayWhatNeedsToBeDisplayed()
{
   switch(whatToDisplay)
   {
      case 1:
           svjetlost();
         break;
      case 2:
          
         break;
   }
}

I don't know how to add the readings from the void collectData into the void determineWhatToDisplay(); and what to put into that. Do I put all whe lcd commands into void determineWhatToDisplay(); or should I put them somewhere else.