Things used in this project

Story

Back when I was going to electronics school in the 80's I built and installed a Night Rider lighting system in a friends camero using a bi-directional shift register to control the lighting effects. When I started experimenting with the Arduino and learned about how to control shift registers with the Arduino I wanted to simulate the Night Rider.

Pinout and Mode of Operation

In this project I use three shift registers to control 24 LEDs. The registers are connected together by taking serial out pin (pin 9) of the first shift register to the serial data input (pin 14) of the second register. Next you take the serial out pin (pin 9) of the second shift register to the serial data input (pin 14) of the third shift register.

The clock pin (pin 11) on all three shift registers are connected and driven by one output from the Arduino.

In this manner when you send the clock signal from the Arduino you will be causing the data to shift simultaneously in all three shift registers. Because a single call to the shiftOut() library function only shifts out one byte you will be calling it three times to update all three registers.

In my code I have a function "updateShiftRegister()" which takes care of setting the latchPin low, shifting out all 24 bits of my current led pattern, then setting the latchPin back high to update the LEDs.

Code

Night Rider CodeC/C++

/*Using three 74HC595s to control 24 leds (outputs) on the arduino uno. This is an improved version by John Rogers*/intlatchPin=5;// to pin 12intclockPin=6;// to pin 11intdataPin=4;// to pin 14intnumLights=24;unsignedlonglight=0;// Bit pattern for entire displaybyteb1=0;// byte place holders for each shift registerbyteb2=0;// extracted from "light"byteb3=0;voidsetup(){pinMode(latchPin,OUTPUT);pinMode(dataPin,OUTPUT);pinMode(clockPin,OUTPUT);// Serial.begin(9600);}voidloop(){for(inti=0;i<numLights*2;i++){intshift=i;if(i>=numLights)//if i is above numlights then wee need to start{// moving back to the left.shift=numLights*2-i-1;}// Extract the bytes of the light patter to be sent outlight=(long)(1)<<shift;b1=(byte)((light>>16)&0xFF);b2=(byte)((light>>8)&0xFF);b3=(byte)((light)&0xFF);updateShiftRegister();// shift out b1, b2 and b3delay(30);}}voidupdateShiftRegister(){digitalWrite(latchPin,LOW);shiftOut(dataPin,clockPin,MSBFIRST,b1);shiftOut(dataPin,clockPin,MSBFIRST,b2);shiftOut(dataPin,clockPin,MSBFIRST,b3);digitalWrite(latchPin,HIGH);}