# Switching OLED screen

**URL:** <https://forum.arduino.cc/t/switching-oled-screen/1078811>\
**Category:** Programming\
**Created:** [January 17, 2023, 8:05pm UTC](https://forum.arduino.cc/t/switching-oled-screen/1078811 "2023-01-17T20:05:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tom321](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tom321/32/1126662_2.png) [@tom321](https://forum.arduino.cc/u/tom321)\
**Post date:** [January 17, 2023, 8:05pm UTC](https://forum.arduino.cc/t/switching-oled-screen/1078811/1 "2023-01-17T20:05:22Z")

</div>

Hi  
I have a program A = switching LCD screen , it is working Ok and program B = switching OLED screen - it is not working, not switching the screen. What I am missing ?  
Program A

```cpp
#include <LiquidCrystal.h> //Library LiquidCrystal
//LiquidCrystal lcd(PA0, PA1, PA2, PA3, PA4, PA5);
LiquidCrystal lcd(PA0, PA1, PA2, PA4, PA5, PB10);

const int buttonPin = PB15; // the number of the pushbutton pin
const int ledPin = PC13; // the number of the LED pin

// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
int disp_mode = 0;
int prestate = 0;
int A;
int B;

void setup() {
  pinMode(buttonPin, INPUT_PULLUP);
  lcd.begin(16, 2);
}

void loop() {

  buttonState = digitalRead(buttonPin);

  if (buttonState == HIGH && prestate == 0) 
  {
    disp_mode++;
    if (disp_mode > 8) // # of screens ++++++++++++++++++++++++++++++
      disp_mode = 0;
    //lcd.setCursor(0, 0);
    lcd.print(" ");
    lcd.setCursor(1, 1);
    // lcd.print(disp_mode);

    if (disp_mode == 0)
    {
      lcd.print("R ");
    }

    if (disp_mode == 1)
    {
      lcd.print("B ");
    }
    if (disp_mode == 2)
    {
      lcd.print("M ");
    }
    if (disp_mode == 3)
    {
      lcd.print("T ");
    }
    if (disp_mode == 4)
    {
      lcd.print("A ");
    }
    if (disp_mode == 5)
    {
      lcd.print("F ");
    }
    if (disp_mode == 6)
    {
      lcd.print("B ");
    }
if (disp_mode == 7)
    {
      lcd.print("V ");
    }
      if (disp_mode == 8)
    {
     lcd.print(" ");
    }
    prestate = 1;
  } else if (buttonState == LOW) {
    prestate = 0;
  }

}

```

Program B

```cpp

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

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

int sensorValue = 0;
int voltage = 0;
const int analogInPin = PA7;
////////
const int buttonPin = PB15; // the number of the pushbutton pin
const int ledPin = PC13; // the number of the LED pin

// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
int disp_mode = 0;
int prestate = 0;
int A;
int B;

void setup() {
  pinMode(buttonPin, INPUT_PULLUP);

 if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C))
 { 
   for(;;); // Don't proceed, loop forever
  }
 
// lcd.begin(16, 2);
}

void loop() {
  
  display.clearDisplay();
  display.setTextSize(4);
  display.setTextColor(WHITE);
  
  buttonState = digitalRead(buttonPin);

  if (buttonState == HIGH && prestate == 0) 
  {
    disp_mode++;
    if (disp_mode > 8) // # of screens ++++++++++++++++++++++++++++++
      disp_mode = 0;
    //lcd.setCursor(0, 0);
  display.print(" ");
   // lcd.setCursor(1, 1);
     display.setCursor(0, 0);
    // lcd.print(disp_mode);

    if (disp_mode == 0)
    {
     display.print("R ");
    }

    if (disp_mode == 1)
    {
      display.print("B ");
    }
    if (disp_mode == 2)
    {
   display.print("M ");
    }
    if (disp_mode == 3)
    {
    display.print("T ");
    }
    if (disp_mode == 4)
    {
      display.print("A ");
    }
    if (disp_mode == 5)
    {
       display.print("F ");
    }
    if (disp_mode == 6)
    {
      display.print("B ");
    }
if (disp_mode == 7)
    {
      display.print("V ");
    }
      if (disp_mode == 8)
    {
     display.print(" ");
    }
    prestate = 1;
  } else if (buttonState == LOW) {
    prestate = 0;
  }

}

```

---

<div class="post-metadata">

**Author:** ![paulpaulson](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paulpaulson/32/363643_2.png) [@paulpaulson](https://forum.arduino.cc/u/paulpaulson)\
**Post date:** [January 17, 2023, 8:26pm UTC](https://forum.arduino.cc/t/switching-oled-screen/1078811/2 "2023-01-17T20:26:36Z")

</div>

Hello [tom321](https://forum.arduino.cc/u/tom321)

Run this tutorial to gain the knowledge.

> **[Arduino - OLED | Arduino Tutorial](https://arduinogetstarted.com/tutorials/arduino-oled)**
>
> Learn how to use OLED display with Arduino, how to display text, number on OLED, how to draw on OLED, how to display image on OLED, how to connect OLED to Arduino, how to code for OLED, how to program Arduino step by step. The detail instruction,...

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [July 16, 2023, 8:27pm UTC](https://forum.arduino.cc/t/switching-oled-screen/1078811/3 "2023-07-16T20:27:27Z")

</div>

Closed on July 16, 2023, 8:27pm UTC

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