IF statement with multiple conditions for Oled

Need help with multiple if statement.


#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <DS3231.h>

DS3231  rtc(SDA, SCL);
Time t;

void setup() {
  Serial.begin(115200);

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.display();
  display.clearDisplay();

  rtc.begin();
  // The following lines can be uncommented to set the date and time
  //After uploading comment back and upload to make static values to that it does not changed after every bootup.
  // rtc.setDOW(WEDNESDAY);     // Set Day-of-Week to SUNDAY
 // rtc.setTime(3, 25, 55);     // Set the time to 12:00:00 (24hr format)
  // rtc.setDate(11, 10, 2021);   // Set the date to January 1st, 2014 (DD,MM,YYYY)

//*************************End of void Setup************************

void loop() {
  Serial.println(rtc.getTimeStr());

  if (t.hour >= 8 && t.hour <= 9) {
    Serial.println ("SUNRISE");
    display.setCursor(80, 20);
    display.print("SUNRISE" );
  }

  else if (t.hour >= 21 && t.hour <= 6) {
    Serial.println ("MOONLIGHT");
    display.setCursor(80, 20);
    display.print("MOONLIGHT" );
  }

  else  {
    Serial.println ("OFF");
    display.setCursor(80, 20);
    display.print(" OFF");
  }
  display.display();
  display.clearDisplay();

}


//*************************End of void loop************************

Do you have a question?

yes display is not printing the status during given period of time. seems like something stuck in void loop. the program is not progressing with if and else if statements.

Your display showing nothing doesn't seem surprising:

  display.display();
  display.clearDisplay();

Send stuff and immediately clear it?

yes exactly.. it shld verify the time given in If statement from RTC whenever it passes through.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.