Problem lighting lights up

Ok no problem:
here is the new code:

[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);

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

}

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

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

bin = convert ( minuteur );
light( bin );
}

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

if (minuteur/16 == 1){
bin.LED16 = true;
reste = minuteur % 16;
}
else{
bin.LED16 = false;
Serial.println (reste);
}
if ( reste/8 == 1){
bin.LED8 = true;
reste = reste % 8;
}
else{
bin.LED8 = false;
Serial.println (reste);
}
if ( reste/4 == 1){
bin.LED4 = true;
reste = reste % 4;
}
else{
bin.LED4 = false;
Serial.println (reste);
}
if (reste/2 == 1){
bin.LED2 = true;
reste = reste % 2;
}
else{
bin.LED2 = false;
Serial.println (reste);
}
if (reste/1 == 1){
bin.LED1 = true;
reste = reste % 1;
}
else{
bin.LED1 = false;
Serial.println (reste);
}
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);
}
}
[/code]

But I don't know how to read the place where it is written. My serial Monitor laggs quite a lot...

Your computing of the Leds in 'convert' is wrong.
Try this:

  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);

  digitalWrite(9, LOW);
  digitalWrite(10, LOW);
  digitalWrite(11, LOW);
  digitalWrite(12, LOW);
  digitalWrite(13, LOW);
  minuteur = 31;

}

void loop() {
  binary bin;
  delay(1000);
  //Serial.println(minuteur);
  bin = convert ( minuteur );
  light( bin );
  if ( --minuteur < 0 ) minuteur = 31;
}

binary convert(int minuteur) {
  binary bin;
  bin.LED16 = LOW;
  bin.LED8 = LOW;
  bin.LED4 = LOW;
  bin.LED2 = LOW;
  bin.LED1 = LOW;
  Serial.println(minuteur);
  if (minuteur / 16 == 1) {
    bin.LED16 = true;
  }
  minuteur = minuteur % 16;
  Serial.println (minuteur);
  if ( minuteur / 8 == 1) {
    bin.LED8 = true;
  }
  minuteur = minuteur % 8;
  Serial.println (minuteur);
  if ( minuteur / 4 == 1) {
    bin.LED4 = true;
  }
  minuteur = minuteur % 4;
  Serial.println (minuteur);
  if (minuteur / 2 == 1) {
    bin.LED2 = true;
  }
  minuteur = minuteur % 2;
  Serial.println (minuteur);
  if (minuteur  == 1) {
    bin.LED1 = true;
  }
  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);
  }
}

thank you so much!!!
You really helped me so much and you were so patient with me!!!
Now the problem is solved thanks to you and I really appreciated your help during this whole time! Really thank you so much!!!
ur the best!
thx :+1: :+1: :pray:

what does this line do?

It counts down the minuteur variable, and if its less than zero its starts over again with 31. That's why you see your leds counting down in binary mode.

The code could also be shortened significantly:

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);

  digitalWrite(9, LOW);
  digitalWrite(10, LOW);
  digitalWrite(11, LOW);
  digitalWrite(12, LOW);
  digitalWrite(13, LOW);
  minuteur = 31;

}

void loop() {
  binary bin;
  delay(1000);
  //Serial.println(minuteur);
  bin = convert ( minuteur );
  light( bin );
  if ( --minuteur < 0 ) minuteur = 31;
}

binary convert(int minuteur) {
  binary bin;
  Serial.println(minuteur);
    bin.LED16 = minuteur & 16;
    bin.LED8 = minuteur & 8;
    bin.LED4 = minuteur & 4;
    bin.LED2 = minuteur & 2;
    bin.LED1 = minuteur & 1;
  return bin;
}

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

And it does the same ...
But maybe that's not for the beginning :wink:

It is very hard for me to understand such a shortened code

10000000000 times thanks again :+1: :+1: :+1: :+1: :pray: :pray: :pray:

You're welcome

Last question:
Why does the binary go backwards? What I mean by that is that the Leds go from 31 to 1 and not from 1 to 31. Where in the code does it say that so I can change it?

It is the line you asked me the meaning of.
Change it to:

 if ( ++minuteur > 31 ) minuteur = 0;

ok thx

Hi,
Can you post a circuit diagram please?
Include your component labels and pin labels.

A pen(cil) and paper drawing will be fine.

Thanks.. Tom.... :grinning: :+1: :coffee: :australia:

what is a component label?

here it is!
It is very simple

A single resistor for multiple LEDs is not generally a good idea because the current through each LED varies according to how many are lit

could it break my leds?

int mettre_a_zero = digitalRead(8)

if( mettre_a_0 == HIGH){
minuteur = 1 ;
}

is this correct ? because it doesn't work...

Do you mean beyond the fact that the digitalRead() line is not terminated with a semicolon and that you read the pin state into mettre_a_0 then test the state of a completely different variable named mettre_a_0

what do you mean by

what do you mean, it's the same variable...
I put the result of digitalRead (8) inside and then I use it for a ''if''

This is what I see in your reply #36

image

could u tell me how to do it correctly then?