If and Else issues, code not working correctly

Hi all

Ok so I have been working on a greenhouse controller, remote in the greenhouse monitoring temperature, humidity and there is also an RTC there.

I have everything being beamed over RF to a small unit I made using on OLED display and RF receiver.

All works great, I get all the data displayed on the OLED screen completely remotely.

What I want the code to do, is when there is no RF signal received, on the OLED it says “no signal”, in my code this works great, I turn off the power in the greenhouse and all that is displayed on the screen is the no signal message, great.

However when there is data being received, temp and humidity are shown, then date and time, and then it should go back to temp and humidity again, but Im very briefly seeing on the screen "no signal", and I have no idea why, Im assuming there is something wrong with the if else statement.

If anyone can guide me by having a quick look, it would be very much appreciated.

Cheers Alan

void loop() {

if (receive.available())         
  {
    receive.read(&data, sizeof(data));
    
    display.display();
    display.clearDisplay();
    display.setTextSize(2);
    display.setTextColor(WHITE);
    display.setCursor(0,5);
    display.print("Humi : ") ;display.print(data.humidity, 0); display.print("%");
    display.setTextSize(2);
    display.setTextColor(WHITE);
    display.setCursor(0,40);
    display.print("Temp : "); display.print(data.temperature, 0); display.print("C");
    display.display();
    delay(2000);
    display.display();
    display.clearDisplay();
    display.setTextSize(1);
    display.setTextColor(WHITE);
    display.setCursor(0,2);
    display.print("Time"); 
    display.setCursor(0,15);
    display.setTextSize(2);
    if (data.tim1 < 10) display.print("0"); display.print(data.tim1, 0); display.print(":");
    if (data.tim2 < 10) display.print("0"); display.print(data.tim2, 0); display.print(":");
    if (data.tim3 < 10) display.print("0"); display.print(data.tim3, 0);
    display.setTextSize(1);
    display.setTextColor(WHITE);
    display.setCursor(0,37);
    display.setTextSize(1);
    display.print("Date"); 
    display.setCursor(0,50);
    display.setTextSize(2);
    if (data.dat1 < 10) display.print("0"); display.print(data.dat1, 0); display.print("-");
    if (data.dat2 < 10) display.print("0"); display.print(data.dat2, 0); display.print("-");
    if (data.dat3 < 10) display.print("0"); display.print(data.dat3, 0);
    display.display();
    delay(2000);
  
  }
    else display.display();
  
    display.setTextSize(1);
    display.setTextColor(WHITE);
    display.setCursor(40,30);
    display.print("No Signal"); 

}

Looks like you are missing a pair of { and } for the else part.

Paul your a star.

Thank you very much, cheers :slight_smile:

If you want more than one statement inside your ‘if’ or ‘else’ you have to put curly braces ‘{}’ around them. Putting them on the same line is not sufficient.