Simpler Code for 7 Segment LED and Shift Register

Hey everyone,

I started learning Arduino recently so that I could complete my Senior Project in my Mechanical Design Degree (yeah, my professor said the same thing...)

Thus far, I have most of the code figured out, and I even have the 7 segment working using a tutorial from buildr but the code just seems really long and when i put all the code together to finish my project, i think it will be excessive.

So is there a way to Shift in all 8 bits into the register (595) without using 8 lines of code?

my current code looks something like this:
if (number == 0) {
//0
setRegisterPin(0, 0);
setRegisterPin(1, 0);
setRegisterPin(2, 0);
setRegisterPin(3, 1);
setRegisterPin(4, 0);
setRegisterPin(5, 0);
setRegisterPin(6, 0);
setRegisterPin(7, HIGH);

writeRegisters();

The code that I am interested in using uses the ShiftOut command:
shiftOut(data, clock, LSBFIRST, zero);

where

byte zero = b11000000;

Any suggestions? or am I doing it about right...?

You can shift it to the 595 in one line using SPI. I have a brief bit of example code here:

That's a nice and thorough example, I must say I appreciate how active and helpful you are on these forums Mr. Gammon. The world needs more like you!

Very cool, I will try this today and let you know how it works out.

but with this code:

...
byte c; <----Can I change "c" to a binary string such as 0110 0000 ?
void loop ()
{
c++;
digitalWrite (LATCH, LOW);
SPI.transfer (c);
digitalWrite (LATCH, HIGH);
delay (20);
...

A binary number? Like this?

byte c = 0b01100000;

I thought the format was

byte c = B01100000;

or do both ways work?

What I suggested works, and I prefer this because it is clear it is a number, and not a variable whose name happens to start with B.

It looks similar to 0x0F (where x is for heX), so 0b01011111 reminds you that the B is for Binary.

After all, B0 is a perfectly valid variable name (like X2 or Y3) so to have B0 really represent a binary number is a bit confusing.

byte c = B01100000;
byte d = 0b01100000;
void setup(){
  Serial.begin(9600);
  Serial.println(c);
  Serial.println(d);
}
void loop(){
}

Apparently both work fine. Only difference (looking at the screen only !) is that the word B01100000 is automatically displayed in blue while the word 0b01100000 is displayed in black as normal text.

That would just be an artifact of the way they have set up syntax colouring in the IDE.