Serial problem

I am having some problems with my code. For now this only turns LED’s on and off but later I would like this to control my smart room.

So here is the problem. I am using a potenciometer to control what is displayed on LCD (some kind of a menu), and a button to accept that. No problem while I am sending data to computer using serial.println. But if I comment that line out - the potenciometer no longer works like it should. I turn it and the display doesn’t change. Only after i press the button the screen changes - or not.

The code:

#include <LCD4Bit.h> 
#define LED 3
#define gumb 4
#define LED2 13

LCD4Bit lcd = LCD4Bit(2); //Ustvari nov zaslon z dvema vrsticama

int vrednost = 0;
int vrednostNaOpcijo = 1023/4;
int prejsnja_vrednost = 0;
int gumbek = 0;
int prizganaLED = 0;
int izbrana_opcija = 0;
int prizgan_zvok = 0;



void setup() { 
  lcd.init();
  pinMode(LED, OUTPUT);
  pinMode(gumb, INPUT);
  pinMode(LED2, OUTPUT);
  Serial.begin(9600);
}

void prikazimeni(int opcija)
{
  lcd.clear();
  
    switch (opcija)
  {
      case 1: lcd.printIn("Ugasni LED"); break;
      case 2: lcd.printIn("Prizgi LED"); break;
      case 3: lcd.printIn("Prizgi zvok"); break;
      case 4: lcd.printIn("Izklopi zvok"); break;
  }
  delay(500);
}

void domov()
{
  
}

void loop() {  
  
  vrednost = analogRead(5);
  Serial.println(vrednost);
  if ((prejsnja_vrednost != vrednost) && (prejsnja_vrednost != vrednost+1) && (prejsnja_vrednost != vrednost-1) && (prejsnja_vrednost != vrednost+2) && (prejsnja_vrednost != vrednost-2))
  {
    if (vrednost <= 255)
    {
        izbrana_opcija = 1;
        prikazimeni(1);
    }
    else if (vrednost <= 510)
    {
        izbrana_opcija = 2;
        prikazimeni(2);
    }
    else if (vrednost <= 765)
    {
        izbrana_opcija = 3;
        prikazimeni(3);
    }
    else if (vrednost <= 1023)
    {
        izbrana_opcija = 4;
        prikazimeni(4);
    }
  }
  
  if (izbrana_opcija == 2)
  {
      gumbek = digitalRead(gumb);
      if (gumbek == 1)
      {
          prizganaLED = 1;
      }
  }
  else if (izbrana_opcija == 1)
  {
      gumbek = digitalRead(gumb);
      if (gumbek == 1)
      {
          prizganaLED = 0;
      }
  }
  else if (izbrana_opcija == 3)
  {
      gumbek = digitalRead(gumb);
      if (gumbek == 1)
      {
          prizgan_zvok = 1;
      }
  }
  else if (izbrana_opcija == 4)
  {
      gumbek = digitalRead(gumb);
      if (gumbek == 1)
      {
          prizgan_zvok = 0;
      }
  }

  
  
  
  if (prizganaLED == 1)
  {
      digitalWrite(LED, HIGH);
  }
  else
  {
      digitalWrite(LED, LOW);
  }
  
  
  if (prizgan_zvok == 1)
  {
      digitalWrite(LED2,HIGH);
  }
  else
  {
      digitalWrite(LED2, LOW);
  }
  
  prejsnja_vrednost = vrednost;

}

So the problem is in Serial.println(vrednost); ← If I delete that the thing stops working. Why?

I'm a newby, so might be wrong. I think the problem is you are setting previous_value = vrednost every time, not in the if (previous != current....) statement. So if there is no slowdown of the code (caused by the println), the value gets reset too fast for the code to ever pick up the change.

You are correct! I am an idiot! Or maybe not - I just don't have any experience with microcontrollers or arduino. I just got it yesterday and I am still getting used to it.

EDIT: We are both wrong! It isn't working. I just added a piece of code that sent some data using serial port and forgot about it. When I removed that the thing stopped working.