Hardware Reference
In-Depth Information
{
//Set pins as outputs
pinMode(SER, OUTPUT);
pinMode(LATCH, OUTPUT);
pinMode(CLK, OUTPUT);
digitalWrite(LATCH, LOW); //Latch low
shiftOut(SER, CLK, MSBFIRST, B10101010); //Shift most sig. bit first
digitalWrite(LATCH, HIGH); //Latch high - show pattern
}
void loop()
{
//Do nothing
}
Because the shift register will latch the values, you need to send them only
one time in the setup; they then stay at those values until you change them to
something else. This program follows the same steps that were shown graphi-
cally in FigureĀ 7-3. The LATCH pin is set low, the 8 bits of data shifted in using
the shiftOut() function, and then the LATCH pin is set high again so that the
shifted values are output on the parallel output pins of the shift register IC.
DAISY CHAINING SHIFT REGISTERS
GettingeightdigitaloutputsfromthreeI/Opinsisaprettygoodtradeoff,but
whatifyoucouldgetevenmore?Youcan!Bydaisychainingmultipleshift
registerstogether,youcouldtheoreticallyaddhundredsofdigitaloutputs
toyourArduinousingjustthreepins.Ifyoudothis,you'llprobablywantto
useabeeierpowersupplythanjustUSB.Thecurrentrequirementsofafew
dozenLEDscanaddupveryquickly.
Recallfromthepin-outinFigure7-2thatthereisanunusedpincalled
Q H '.Whentheoldestvalueisshiftedoutoftheshiftregister,itisn'tdis-
carded;it'sactuallysentoutonthatpin.ByconnectingtheQ H 'totheDATA
pinofanothershiftregister,andsharingtheLATCHandCLOCKpinswiththe
irstshiftregister,youcancreatea16-bitshiftregisterthatcontrolstwice
asmanypins.
Youcankeepaddingmoreandmoreshiftregisters,eachconnectedtothe
lastone,toaddacrazyofnumberoutputstoyourArduino.Youcantrythis
outbyhookingupanothershiftregisterasdescribedandsimplyexecuting
the shiftOut() function inyourcodetwice.(Eachcallto shiftOut() can
handleonly8bitsofinformation.)
 
Search WWH ::




Custom Search