Code in the arduino is fine but the display show nothing

Hi, i am working on my project to school on this week and i am doing legendary Ping pong game in arduino. when i hit the upload button it shows me the code is fine, but nothing appears on the display. Please help me i am desperate

Here is the code :

SSH1106.ino

#include <GyverOLED.h>
#include "Joystick.h"
#include "pong.c"

const int GAME_OVER_SCORE = 10;
const int GAME_SPEED = 40;  //You can go up to 60

const int SCREEN_WIDTH = 128;
const int SCREEN_HEIGHT = 64;

unsigned long last_tick;

int cpu_score = 0;
int player_score = 0;
int state = 0;

GyverOLED<SSH1106_128x64> screen;

void tick(int fps){
  unsigned long fps_delay = 1000/fps;
  last_tick += fps_delay;
  unsigned long time_to_delay = last_tick - millis();
  unsigned long wait = max(0, time_to_delay);
  if ( wait > 0){
    delay(time_to_delay);
  }
  else{ 
    last_tick = millis();
  }
}

class Paddle {

 protected:
 void LimitMovement()
 {
   if(y < 0)
   {
     y = 0;
   }
   if( y+ height >= screen_height)
   {
     y = screen_height - height;
   }
 } 
 public:
 int x, y;
 int width, height;
 int speed;
 int screen_height;

  void Draw(){
    screen.rect(x, y, x+width, y+height, OLED_FILL);
  }

  void Update(char keyPressed)
  {
    if(keyPressed == 'U')
    {
      y -= speed;
    }
    if(keyPressed == 'D')
    {
      y += speed;
    }
    LimitMovement();
  }
};

class Ball{
  public:
  int x, y;
  int radius;
  int speed_x;
  int speed_y;

  void Draw(){
    screen.circle(x, y, radius, 1);
  }

  void Update(Paddle &player, Paddle &cpu) {
    x += speed_x;
    y += speed_y;

    if (y + radius >= SCREEN_HEIGHT - 1)
    {
        speed_y *= -1;
        y = SCREEN_HEIGHT - 1 - radius;
    }
    
    if( y - radius <= 1) {
      speed_y *= -1;
    }

    if (x + radius >= SCREEN_WIDTH - 1){
        cpu_score ++;
        ResetBall();
    }
    
    if( x - radius <= 1){
      player_score++;
      ResetBall();
    }

    if ((x - radius <= cpu.x + cpu.width) && (y + radius > cpu.y) && (y-radius < cpu.y + cpu.height))
    {
      speed_x *= -1;
    }

     if ((x + radius >= player.x) && (y + radius > player.y) && (y-radius < player.y + player.height))
    {
      speed_x *= -1;
    }
  }

  void ResetBall()
  {
    x = SCREEN_WIDTH/2;
    y = SCREEN_HEIGHT/2;
  }
};

class CpuPaddle :public Paddle{
  public:
  void Update(Ball &ball)
  {
    if (ball.y > y  && ball.speed_x < 0 && ball.x < SCREEN_WIDTH/2)
    {
      y += speed;
    }
    if (ball.y < y + height && ball.speed_x < 0 && ball.x < SCREEN_WIDTH/2)
    {
      y -= speed;
    }
    LimitMovement();
  }
};

void printScore(int x, int y, int score){
  screen.setCursorXY(x, y);
  screen.setScale(1);
  screen.print(score);
}

void gameOverScreen() {
  screen.clear();
  screen.rect(0, 0, SCREEN_WIDTH-1, SCREEN_HEIGHT-1, OLED_STROKE);
  screen.setCursorXY(35, 10);
  screen.print("GAME OVER!");
  if(player_score >= cpu_score)
  {
    screen.setCursorXY(28, 28);
    screen.print("PLAYER WINS!");
  }else
  {
    screen.setCursorXY(38, 28);
    screen.print("CPU WINS!");
  }
  screen.update();
}

void startScreen() {
  screen.clear();

  screen.drawBitmap(0, 0, pong, 128, 64, BITMAP_INVERT, BUF_ADD);
  screen.update();
}

Ball ball;
Paddle player;
CpuPaddle cpu;
Joystick joystick;

void setup(void) {
  Serial.begin(9600);
  initDisplay();
  Wire.setClock(800000L);
  last_tick = millis();

  ball.x = SCREEN_WIDTH/2;
  ball.y = SCREEN_HEIGHT/2;
  ball.radius = 3;
  ball.speed_x = 2;
  ball.speed_y = 2;

  cpu.width = 2;
  cpu.height = 16;
  cpu.x = 3;
  cpu.y = (SCREEN_HEIGHT-1)/2 - cpu.height/2;
  cpu.speed = 2;
  cpu.screen_height = SCREEN_HEIGHT;

  player.width = 2;
  player.height = 16;
  player.x = (SCREEN_WIDTH-1) - player.width - 3;
  player.y = (SCREEN_HEIGHT-1)/2 - player.height/2;
  player.speed = 2;
  player.screen_height = SCREEN_HEIGHT;
  startScreen();
}

void loop() {

  joystick.ReadYaxis();
  Serial.println(joystick.keyPressed);

  if (state == 2) {
    gameOverScreen();
    if(joystick.keyPressed == 'U' || joystick.keyPressed == 'D')
    {
      state = 0;
      player_score = 0;
      cpu_score = 0;
    }

  }else if (state == 1)
  {
    screen.clear();
    screen.fastLineV(SCREEN_WIDTH/2, 0, SCREEN_HEIGHT, 1);
    ball.Update(player, cpu);
    cpu.Update(ball);
    player.Update(joystick.keyPressed);
    ball.Draw();
    player.Draw();
    cpu.Draw();
    printScore(SCREEN_WIDTH/4,2,cpu_score);
    printScore(3*SCREEN_WIDTH/4,2,player_score);
    screen.update();
    if(player_score == GAME_OVER_SCORE || cpu_score == GAME_OVER_SCORE)
    {
      state++;
    }
    
  }else if (state == 0)
  {
    Serial.println("State 0");
    if(joystick.keyPressed == 'U' || joystick.keyPressed == 'D')
    {
      state ++;
    }
  }
  tick(GAME_SPEED);
}

void initDisplay(){
  screen.init();  
  screen.clear();   
  screen.update(); 
}

Joystick.cpp :

#include "Arduino.h"
#include "Joystick.h"

void Joystick::ReadYaxis()
{
  yValue = analogRead(A1); 
  if(yValue < 100)
  {
    keyPressed = 'U';
  }
  else if(yValue > 900)
  {
    keyPressed = 'D';
  }else
  {
    keyPressed = ' ';
  }
}

Joystick.h :

class Joystick {

  int yValue;

  public: 
    char keyPressed;
    void ReadYaxis();
};

pong.c :

const unsigned char pong [] = {
0x00, 0x00, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC,
0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC,
0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC,
0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 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3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
0x3E, 0x3D, 0x3D, 0x3D, 0x3F, 0x3F, 0x3E, 0x3D, 0x3D, 0x3C, 0x3D, 0x3F, 0x3C, 0x3D, 0x3D, 0x3C,
0x3D, 0x3E, 0x3D, 0x3D, 0x3F, 0x3F, 0x3E, 0x3D, 0x3D, 0x3E, 0x3F, 0x3D, 0x3D, 0x3C, 0x3F, 0x3F,
0x3D, 0x3F, 0x3F, 0x3F, 0x3C, 0x3D, 0x3F, 0x3E, 0x3D, 0x3E, 0x3F, 0x3F, 0x3F, 0x3F, 0x00, 0x00
};

PLEASE HELP OR I WILL FAIL MY GRADUATION

When is this due?
Where did you get this code?
Post a schematic of how everything is connected.
Please don't type in all caps.

Have you tested that your display is working and connected correctly by running one of the example sketches that come with the library?

1 Like

No i didn't. I am new to this and i dont know to do it

I am doing this project from youtube. If you type ,,ping pong arduino game" it's the video with the joystick with it and in description is the code. there is a picture how to connect it and i connected it the same

You should show some more on effort.
The minimum is to post a link to that youtube video.
There is a high chance that your hardware is somewhere a little bit different than the hardware shown in the video.

Again the question when is this due?
When do you have to have finished the project?
Post a date and time

best regards Stefan

Let me help you... study your subject matter and you will pass everything in life.

The bitmap...
canvas

The game uses a Raspberry Pi Pico.

yeah sorry. link : https://www.youtube.com/watch?v=7DlhFy_pxAk&ab_channel=educ8s.tv

I have a week to finish this work and give it to lectors.

Are you using this microcontroller

flipped 180 degrees for easier reading

What is your exact type of microcontroller?
Is it an Rasperry Pi pico?

or something different?

OK one week this means in seven days which is Thursday 04.01.2024
so you have to be finished on Wednesday 03.01.2024 in the evening?

I insist on very clear communication.
Confirm or correct the date when you have to be finished in the evening because on the next morning you have to handover it to the lectors.

Post pictures of your microcontroller If you have a different microcontroller it might be that this microcontroller does not have enough memory for flashing (and playing) the game.

We should clarify that as soon as possible so you have the chance to order Rasperry Pi pico

Post the datasheet and a picture of your display
If the display has a different driver-chip your code must be adapted to this different driver-chip

Can you estimate now that you have a week full of work for finishing this project?

best regards Stefan

You assignment was to copy someone else's project off of YouTube?

We could choose whatever we like. I will give him credit at the end of my work. Could you help me with it ?

I have 11 days on finishing this work.
And here are the photos of display and microcontroller



Drawing a schematic would be helpful. It's difficult to tell from the pictures.

If you watch this video : https://www.youtube.com/watch?v=7DlhFy_pxAk&ab_channel=educ8s.tv

I have it connected exactlly like him, even the code is same and it doesn't work somehow

I'm asking you to look at your work and draw a schematic of how you have it connected.

The interesting information is here

freehand drawing is sufficient

draw a freehand schematic to what IO-Pins did you connect which display-pin

Do you have a digital multimeter?
do you know how to measure current?
alternatively can you provide a datasheet of your display or at least a link where you have bought it?

I dont have multimeter on me right now.
Here is the link to display : 1.3" White OLED LCD 4PIN Display Module IIC I2C Interface 128x64 for Arduino | eBay

How are you powering this?

please post the complete sketch as a code-section
like described in this tutorial