OLED displaying weird stuff

Ok, so i am completely new to arduino (this is my first project), and i am just making a project for physics, i did everything according to some tutorial on youtube, but my OLED display is displaying just weird white lines, it is supposed to be distance measuring device and i have no idea what went wrong. I am posting the code here so please let me know cause i need to fix it by tuesday or i get a bad mark:

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

#define triPin 13 //Pulse pin
#define echoPin 12

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

void setup() {
Serial.begin (9600);
pinMode(triPin, OUTPUT);
pinMode(echoPin, INPUT);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //initialize with the I2C addr 0x3C (128x64)


void loop() {
long duration, distance;

digitalWrite(triPin, LOW); //PULSE
digitalWrite(triPin, HIGH);
digitalWrite(triPin, LOW);

duration = pulseIn(echoPin, HIGH);

#ifdef SenseMetricSystem
distance = (duration / 2) / 29.1;

display.setCursor(5, 1);

display.setCursor(15, 30); //OLED Display
display.setCursor(80, 30);

#ifdef SenseMetricSystem





Check the wiring, pull-ups on the I2C lines etc.
Junk all the sonar code, and concentrate on getting the display working. Then add back the sonar code when you know it is working using serial prints.

Please remember to use code tags when posting code.

I have absolutely no idea how the coding works, so i won't be able to fix it myslef. If someone would be so kind to post the repaired code here i would be glad.

You’ll get a better mark, but what’s our motivation?

i have spent the last 3 hours looking at tutorials trying to fix it, but it's always the same, just white boxes and nothing else, i have no idea what to do, nothing i do changes anything. i think i am just gonna give up honestly.


ok so i fixed it in the codes, finally, but it still shows these white boxes and even more of them now, so do you guys think there is something wrong with the display itself? and if so, any idea on how to fix it?

Does the number of boxes correlate to the number of characters you're printing?

well yes, the more i type in there, the more white stuff shows on the display