HIGH without digitalWrite

I have leds connected to the digital port 3 to 13.
I have OUTPUT ports 6 to 9
I write at random the port 6 to 9 HIGH.
My problem is that if port 9 becomes HIGH: port 10 becomes also HIGH
How is that possible?

My code is:

const int LED1 = 6;
const int LED2 = 7;
const int LED3 = 8;
const int LED4 = 9;


int LEDX = LED1;

void setup () 
{
  pinMode (LED1, OUTPUT);
  pinMode (LED2, OUTPUT);
  pinMode (LED3, OUTPUT);
  pinMode (LED4, OUTPUT);
}
  
 void loop ()
{
 LEDX = random(LED1,LED4 + 1); 
 
 switch (LEDX) {
   
   case LED1:
     digitalWrite(LED1, HIGH);
     delay(1000);
     digitalWrite(LED1, LOW);
     break;
     
   case LED2:
    digitalWrite(LED2, HIGH);
    delay(1000);
    digitalWrite(LED2, LOW);
    break;
    
  case LED3:
    digitalWrite(LED3, HIGH);
    delay(1000);
    digitalWrite(LED3, LOW);
    break;
    
 case LED4:
    digitalWrite(LED4, HIGH);
    delay(1000);
    digitalWrite(LED4, LOW);
    break;
  }
}

moderator update: added code tags ==> # button above smileys

louis14:
I have leds connected to the digital port 3 to 13.
I have OUTPUT ports 6 to 9
I write at random the port 6 to 9 HIGH.
My problem is that if port 9 becomes HIGH: port 10 becomes also HIGH
How is that possible?

the voltage on PIN 10 may float about unless you set it to input or output.

I can't see in your sketch where you are setting pin10 to output for your LED

How is that possible?

Ports are named. Pins are numbered. There is NO port 9 or port 10.

Most likely, you have a wiring error.

What very odd code.
Why is there a switch statement in there? Just replace the body of one of those cases with LEDX for on and off and the code is a whole lot shorter.

Grumpy_Mike:
What very odd code.
Why is there a switch statement in there? Just replace the body of one of those cases with LEDX for on and off and the code is a whole lot shorter.

yup… can be replaced with something like this:

void loop()
{
  digitalWrite(random(6,9),HIGH);
  delay(1000);
  for (int i = 6; i < 10; i++)
  {
    digitalWrite(i,LOW);
  }
}

Well I was thinking more of:-

const int LED1 = 6;
const int LED2 = 7;
const int LED3 = 8;
const int LED4 = 9;


int LEDX = LED1;

void setup () 

  {

  pinMode (LED1, OUTPUT);

  pinMode (LED2, OUTPUT);

  pinMode (LED3, OUTPUT);
  
  pinMode (LED4, OUTPUT);
  
  }
  
 void loop ()
{
 LEDX = random(LED1,LED4 ); 
   
     digitalWrite(LEDX, HIGH);
     delay(1000);
     digitalWrite(LEDX, LOW);
}
[/quote]

Thanks for your code.
Now the problem disappeared

Hi, did you guys just get sucked in to write code for someone?

To........ :~

TomGeorge:
Hi, did you guys just get sucked in to write code for someone?

To........ :~

Well no.
He had already written some code what we did was shorten it. In my book that is fine. Sometimes it is a lot easier to do that than to tell someone the structure.