"display was not declared on this scope" while using oled display

Hello,

I am new here. I am working on an automated sprinkler system using ds3231. I chose to use an oled display as the display. but when I try to upload it, there is an error message always.
this is my code,

#include "DS3231lib.h"
#include "Wire.h"
#include "Adafruit_GFX.h"
#include "Adafruit_SSD1306.h"
#include "SPI.h"

int Relay = 4;

DS3231lib rtc(SDA, SCL);
Time t;

const int OnHour1 = 06;
const int OnMin1 = 00;
const int OnHour2 = 18;
const int OnMin2 =00;
const int OffHour1 = 06;
const int OffMin1 = 15;
const int OffHour2 = 18;
const int OffMin2 = 15;

void setup() {
Serial.begin(115200);
rtc.begin();
pinMode(Relay, OUTPUT);
digitalWrite(1,OUTPUT);
digitalWrite(Relay, LOW);
SPI.begin();
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.display();
testscrolltext();
display.clearDisplay();
display.display();
}

void loop() {
t = rtc.getTime();
display.display(); // this is the error line
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(20,0);
display.print(" hour - ");
display.print(t.hour);
display.println(" minute - ");
display.print(t.min);
delay (5000);
display.clearDisplay();
display.display();

if(t.hour == OnHour1 && t.min == OnMin1){
digitalWrite(Relay,HIGH);
Serial.println("Sprinkler turning on");
}

else if(t.hour == OffHour1 && t.min == OffMin1){
digitalWrite(Relay,LOW);
Serial.println("Sprinkler turning off");
}
if (t.hour == OnHour2 && t.min == OnMin2 ){
digitalWrite(Relay, HIGH);
Serial.println("Sprinkler turning on");

}
else if (t.hour == OffHour2 && t.min == OffMin2){
digitalWrite(Relay, LOW);
Serial.println("Sprinkler turning off");
}

}

The error message is 'display' was not declared on this scope.

please help me

Hi Anasura,

imagine you want to order a pizza just saying "I want a pizza"

You will be asked back some questions:

  • where do you want to eat the pizza restaurant or at home?
  • what should be on the pizza?
  • what size shall the pizza have?

Now a pizza is a much lesser complex thing than an Arduino.
This means you have to provide more information to get help
This is the reason why there is a sticky post at the top of the forum
so please read it it.

How to get the best out of this forum

best regards Stefan

The error message is 'display' was not declared on this scope.

So where is display declared ?

If you look at

DS3231lib  rtc(SDA, SCL);

you will see an instance of the DS3231 library named rtc being created for use later in the sketch

Where is the equivalent instantiation of the display object ?

anusara2006:
The error message is 'display' was not declared on this scope.

please help me

Indeed. Furthermore, display is not declared at all.

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