Problem lighting lights up

Hello,
I'm a begginner at arduino .I have descided to do my first own program and it is full of mistakes!! :sweat_smile: .

This problem is quite complicated nd I can't fix it neither on my own neither with my family members...
I have a program that takes a variable and then turns it into a series of leds (using the binary system). My problem is that everythings seems to work but when I upload it the leds are all lit up when they shouldn't...
Here is the code:

struct binary{
bool LED1;
bool LED2;
bool LED4;
bool LED8;
bool LED16;
};

int minuteur = 0;
void light( binary );
binary convert( int);

void setup() {

pinMode(8, INPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
Serial.begin(9600);
}

void loop() {
minuteur = 17;
delay(5000);
Serial.println(minuteur);

binary bin;
/*bin.LED1 = true;
bin.LED2 = false;
bin.LED4 = true;
bin.LED8 = false;
bin.LED16 = true; */

light( bin );
convert (minuteur);
}

binary convert(int minuteur){
binary bin;
minuteur = 4;
delay (5000);
int reste = 0;
bin.LED16,bin.LED8, bin.LED4, bin.LED2, bin.LED1 = LOW;

if (minuteur/16 == 1){
bin.LED16 = true;
reste = minuteur % 16;
}
if ( reste/8 == 1){
bin.LED8 = true;
reste = reste % 8;
}
if ( reste/4 == 1){
bin.LED4 = true;
reste = reste % 4;
}
if (reste/2 == 1){
bin.LED2 = true;
reste = reste % 2;
}
if (reste/1 == 1){
bin.LED1 = true;
reste = reste % 1;
}
return bin;
}

void light(binary bin){
if (bin.LED1){
digitalWrite(13, HIGH);
}
else {
digitalWrite(13, LOW);
}
if (bin.LED2){
digitalWrite(12, HIGH);
}
else {
digitalWrite(12, LOW);
}
if (bin.LED4){
digitalWrite(11, HIGH);
}
else {
digitalWrite(11, LOW);
}
if (bin.LED8){
digitalWrite(10, HIGH);
}
else {
digitalWrite(10, LOW);
}
if (bin.LED16){
digitalWrite(9, HIGH);
}
else {
digitalWrite(9, LOW);
}
}

PS: English isn't my native language so I'm sorry if there are some spelling/vocabulary errors...
PSS: Sorry if the code is not properly formated but it didn't work: it readPreformatted textwhen i did it.

Turn them all off in setup() after setting their pinMode()

I turned them of in the "binary convert " function: bin.LED16,bin.LED8, bin.LED4, bin.LED2, bin.LED1 = LOW;

And how do I turn them all off in the setup() pert?(what is the syntax)

Do you know how to turn one of them off ?

yes
It's with digitalWrite()

Do you know how to turn one of them on then ?

yes
Thx but when I do it all of the LEDs stay bright; At first all of them are dark but then they all turn bright
this is what I did:

void setup() {

pinMode(8, INPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
Serial.begin(9600);

digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, LOW);

}

This does not what you think it should do. Only bin.LED1 is set to LOW.

Switch on the warnings in 'preferences' and the compiler will tell you.

how do I do that?

Press ctrl+, (or Menu file->preferences) and in the opening window set 'compiler warnings' to 'all'

ok
I did this :

indent preformatted text by 4 spaces  bin.LED16 =LOW;

bin.LED8 = LOW;
bin.LED4 = LOW;
bin.LED2 = LOW;
bin.LED1 = LOW;
``
is it better?

That looks much better :slightly_smiling_face:

but it still doesn't work...
I D'ONT KNOW WHAT TO DO!! :sob:

You should first convert, and then switch the lights accordingly. And you must evaluate the return value of your convert:
bin = convert (minuteur);
light( bin );

thank you very much for beeing very patient with me but it says that "minuteur" was not declared in this scope

I don't understand because I have declared it in the function convert and at the begining of void loop()

Did you get this error before? And what did you change? It is important in which line the compiler complains this error

No I didn't have this error before .

I changed light( bin ); convert (minuteur);

into bin = convert ( miuteur ); light( bin );

The error is at line 43 ( bin = convert ( miuteur ); )

There is a typo: minuteur -> miuteur

the error message is gone but now none of the leds are lit up
I don't understand

You can add some Serial.print statements to see what happens in your functions.