Shift Register Most and Least Significant

Hey, I just realised that my arduino kit came with a 74HC595 shift register and I decided to give it a try, I managed to wire it up and spent hours researching for tutorials about the coding but most of them were a bit confusing but I managed to write a code that blinks every odd number LEDs and then blink every even number LEDs. But I want to know what MSBFIRST and LSBFIRST work as i’m just blindly typing it in the code to see which one works. Thanks

The bits correspond to LEDs. Try sending 0x01 using MSBFIRST and LSBFIRST. The difference should be immediately obvious.

Thanks for the reply, the problem is that my code is different and I don't know how to try out the code you gave me. I'll post my code so you can see and tell me if this can be simplified to an easier way. Thanks

int latchPin = 4;             //595 pin 12
int clockPin = 3;          //595 pin 11
int dataPin = 2;           //595 pin 14
//595 pin 16 has 5VDC
//595 pin 8 has GND

void setup() {
 pinMode(latchPin, OUTPUT);
 pinMode(clockPin, OUTPUT);
 pinMode(dataPin, OUTPUT);
}
void loop() {
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, MSBFIRST, B10101010);
   digitalWrite(latchPin, HIGH);
   delay(500);
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, MSBFIRST, B01010101);
   digitalWrite(latchPin, HIGH);
   delay(500);
}

LSB means "least significant bit". MSB means "most significant bit".

For a binary number:

00000001 - the "1" is the least significant bit

And:

10000000 - the "1" is the most significant bit

It's like the number 42. The four is "more significant" than the 2 in the sense that it represents 40 rather than 4.

So with "shift out" it tells you whether it will shift the bit from the left end or the right end.

So if i type MSBFIRST, B10101010; that means the leds start from the left and to the right and vice versa? And is there another way of typing the code cause I've seen many tutorial that uses the 0x01 thing?

0xAA is hex (numbers from 0 to F), is equal to 0b10101010, is equal to 170 decimal 0x55 is 0b01010101, is equal to 85 decimal 0b0000 = 0x0 0001 = 1 0010 = 2 0011 = 3 0100 = 4 0101 = 5 0110 = 6 0111 = 7 1000 = 8 1001 = 9 1010 = A 1011 = B 1100 = C 1101 = D 1110 = E 1111 = F

If you have a Windows computer, open the calculator in scientific view, can convert the formats there for the bigger numbers

So if I were to write it in Hex format, what would I have to do and is my code another way to telling the shift register what to do?

Navin2012: So if i type MSBFIRST, B10101010; that means the leds start from the left and to the right and vice versa?

Yes. In your case MSBFIRST would start with a 1 (the one on the left).

Navin2012: So if I were to write it in Hex format, what would I have to do and is my code another way to telling the shift register what to do?

Based on what CrossRoads posted, to send B10101010 an alternative would be 0xAA (the bit patterns are the same if you check his table).

It's just different ways of looking at the same number.

0b10101010 (binary) == 0xAA (hex) == 170 (decimal).

It's the same number, just written different ways. The binary way is useful if you are visualizing 8 LEDs because you see 8 on/off things.

Sure:

shiftOut(dataPin, clockPin, MSBFIRST, B10101010); instead use shiftOut(dataPin, clockPin, MSBFIRST, 0xAA);

or shiftoutdata = 0xAA; shiftOut(dataPin, clockPin, MSBFIRST, shiftoutdata);

Wow! Thanks everyone for helping out. It’s actually pretty easy once I know what different codes mean. Thanks CrossRoads for bringing up the HEX format. I’m going to try to learn the codes.

No problem. Go browse the reference page, you can pick up a lot there.
If you search the old forum for
ArduinoLanguageReference.pdf
you may be able to find the document where someone went to the trouble of collecting all that stuff in one place so you can print it out and sit back for a good read, take notes, etc.