Switching OLED screen

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

#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


#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;
  }

}

Hello tom321

Run this tutorial to gain the knowledge.