Question regarding a 74HC595 program

Hello,

I wrote 2 simple programs with respect to a simple 74HC595 schematic. The first program is shorter but not working properly. The second program is working fine. The first program supposes to be turning all LEDs OFF and then all ON in unisome. However, when running the first program, the LEDs 4th, 5th and 6th remained off. Can someone please tell me what can be wrong? Why are those LEDS remaining off..

When I try to run the second program to turn all LEDS ON one after another, everything is working fine. So, the issue is only with the first program.

int clockpin = 10;
int latchpin =11;
int datapin = 12;

byte LED0s = 00000000;
byte LED1s = 11111111;

void setup() {
  // put your setup code here, to run once:

  pinMode (clockpin, OUTPUT);
  pinMode (latchpin, OUTPUT);
  pinMode (datapin, OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite (latchpin, LOW);
  shiftOut(datapin, clockpin, LSBFIRST, LED0s);
  digitalWrite (latchpin, HIGH);

  delay (1000);

  digitalWrite (latchpin, LOW);
  shiftOut(datapin, clockpin, LSBFIRST, LED1s);
  digitalWrite (latchpin, HIGH);

  delay (1000);
}
int latchPin= 11;
int clockPin = 10;
int dataPin = 12;
int t =300;

byte LED0s =  0b00000000;
byte LED1s =  0b00000001;
byte LED2s =  0b00000011;
byte LED3s =  0b00000111;
byte LED4s =  0b00001111;
byte LED5s =  0b00011111;
byte LED6s =  0b00111111;
byte LED7s =  0b01111111;
byte LED8s =  0b11111111;

void setup (){
// Serial.begin (9600);
pinMode (latchPin, OUTPUT);
pinMode (dataPin, OUTPUT);
pinMode (clockPin, OUTPUT);

}

void loop(){



delay (t);

digitalWrite (latchPin, LOW);
shiftOut (dataPin, clockPin, LSBFIRST, LED1s);
digitalWrite (latchPin, HIGH);

delay (t);

digitalWrite (latchPin, LOW);
shiftOut (dataPin, clockPin, LSBFIRST, LED2s);
digitalWrite (latchPin, HIGH);


delay (t);

digitalWrite (latchPin, LOW);
shiftOut (dataPin, clockPin, LSBFIRST, LED3s);
digitalWrite (latchPin, HIGH);

delay (t);

digitalWrite (latchPin, LOW);
shiftOut (dataPin, clockPin, LSBFIRST, LED4s);
digitalWrite (latchPin, HIGH);

delay (t);

digitalWrite (latchPin, LOW);
shiftOut (dataPin, clockPin, LSBFIRST, LED5s);
digitalWrite (latchPin, HIGH);

delay (t);

digitalWrite (latchPin, LOW);
shiftOut (dataPin, clockPin, LSBFIRST, LED6s);
digitalWrite (latchPin, HIGH);


delay (t);

digitalWrite (latchPin, LOW);
shiftOut (dataPin, clockPin, LSBFIRST, LED7s);
digitalWrite (latchPin, HIGH);

delay (t);

digitalWrite (latchPin, LOW);
shiftOut (dataPin, clockPin, LSBFIRST, LED8s);
digitalWrite (latchPin, HIGH);

delay (t);



digitalWrite (latchPin, LOW);
shiftOut (dataPin, clockPin, LSBFIRST, LED7s);
digitalWrite (latchPin, HIGH);

delay (t);

digitalWrite (latchPin, LOW);
shiftOut (dataPin, clockPin, LSBFIRST, LED6s);
digitalWrite (latchPin, HIGH);


delay (t);

digitalWrite (latchPin, LOW);
shiftOut (dataPin, clockPin, LSBFIRST, LED5s);
digitalWrite (latchPin, HIGH);

delay (t);

digitalWrite (latchPin, LOW);
shiftOut (dataPin, clockPin, LSBFIRST, LED4s);
digitalWrite (latchPin, HIGH);

delay (t);

digitalWrite (latchPin, LOW);
shiftOut (dataPin, clockPin, LSBFIRST, LED3s);
digitalWrite (latchPin, HIGH);

delay (t);

digitalWrite (latchPin, LOW);
shiftOut (dataPin, clockPin, LSBFIRST, LED2s);
digitalWrite (latchPin, HIGH);


delay (t);

digitalWrite (latchPin, LOW);
shiftOut (dataPin, clockPin, LSBFIRST, LED1s);
digitalWrite (latchPin, HIGH);

delay (t);

digitalWrite (latchPin, LOW);
shiftOut (dataPin, clockPin, LSBFIRST, LED0s);
digitalWrite (latchPin, HIGH);

delay (t);


}

byte LED0s = 00000000;
byte LED1s = 11111111;

You forgot "0b" in front, so this is not binary

You are storing integer 11111111 in a byte, which overflows and the resulting value is 199 (11111111 % 256), which in binary is 0b11000111, explaining why you see LEDs 4 5 and 6 off :slight_smile:

guix:

byte LED0s = 00000000;

byte LED1s = 11111111;




You forgot "0b" in front, so this is not binary

You are storing integer 11111111 in a byte, which overflows and the resulting value is 199 (11111111 % 256), which in binary is 0b11000111, explaining why you see LEDs 4 5 and 6 off :)

Oh! My...my.... my ....
Thank you so much for your sharp eyes.
I was about to loose my mind over this.
Merci beaucoup