'display' was not declared in this scope

Hi,

I was trying to upload a bit of code to my arduino and I keep getting this error message:

C:\Users\Blue Electronics\Downloads\My_Watlow\My_Watlow.ino: In function 'void setup()':

My_Watlow:22:3: error: 'display' was not declared in this scope

   display.begin(SSD1306_SWITCHCAPVCC, 0x3D);

   ^

C:\Users\Blue Electronics\Downloads\My_Watlow\My_Watlow.ino: In function 'void loop()':

My_Watlow:29:3: error: 'display' was not declared in this scope

   display.setTextSize(1);

   ^

exit status 1
'display' was not declared in this scope

Here is the code:

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <max6675.h>
int thermoDO = 7;
int thermoCS = 5;
int thermoCLK = 6;
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
int val;
int encoder0PinA = 3;
int encoder0PinB = 4;
int encoder0Pos = 0;
int encoder0PinALast = LOW;
int n = LOW;

void setup() {
  pinMode (9, OUTPUT);
  pinMode (10, OUTPUT);
  pinMode (encoder0PinA, INPUT);
  pinMode (encoder0PinB, INPUT);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3D);
  display.display();
  display.clearDisplay();
  delay(2500);
}

void loop() {
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0, 0);
  display.println("F= ");
  display.println(thermocouple.readFahrenheit());
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0, 10);
  display.println("F= ");
  display.println(encoder0Pos);
  display.display();
  delay(2000);
  display.clearDisplay();
  n = digitalRead(encoder0PinA);
  if ((encoder0PinALast == LOW) && (n == HIGH)) {
    if (digitalRead(encoder0PinB) == LOW) {
      encoder0Pos--;
    } else {
      encoder0Pos++;
      if (thermocouple.readFahrenheit() > encoder0Pos) {
        digitalWrite(10, LOW);// set pin 10 LOW
      } else {
        digitalWrite(10, HIGH);// set pin 10 HIGH
        if (thermocouple.readFahrenheit() > encoder0Pos) {
          digitalWrite(9, HIGH);
          delay(5000);
          digitalWrite(9, LOW);
        } else {
          digitalWrite(9, LOW);
        }
        delay(1000);
      }
    }}      
}

You have not defined an object named 'display', yet you are class calling methods on it.

Do this:
File > Examples > Adafruit SSD1306 > pick any example sketch
Spend some time carefully studying the example, especially the line that looks something like this:

Adafruit_SSD1306 display(OLED_RESET);
1 Like

Thank you!