3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

The 74HC164 Shift Register and your Arduino

Step 5Project 1[pt 2]: '2 Wire' bargraph LED display controller software

Project 1[pt 2]: \
«
  • PDR_0105.JPG
  • msls.jpg
Example 1:
Open the file " _164_bas_ex.pde" Inside the arduino IDE, Its a simple sketch that just lets you define on or off  LED's in the bargraph display

The first 2 lines define the pin numbers we will be using for data and clock, I use #define over const integer, I find it easier to remember, and there is no advantage to one or the other once compiled

#define data 2
#define clock 3


next is the void setup function, it only runs once, so the arduino turns on, sets the shift register and has nothing else to do. Inside the void setup function we set the clock and data pins as OUTPUT pins, then using the shiftOut function we send the data to the shift register

void setup()
{
  pinMode(clock, OUTPUT); // make the clock pin an output
  pinMode(data , OUTPUT); // make the data pin an output
  shiftOut(data, clock, LSBFIRST, B10101010); // send this binary value to the shift register
}


In the shiftOut function you can see its arguments
data is the data pin, clock is the clock pin

LSBFIRST refers to what order its in, when writing it out in binary notation (Bxxxxxxxx) the 7th element past the B is the Least Signifigant Bit First, this is fed in first so it ends up on the last output once all 8 bits are fed in

B10101010 is the Binary value being sent to the shift register, and it will turn on every odd light, try playing with different values to turn on or off different patterns

and finally a empty void loop (because you need one even if your not using it)

void loop(){} // empty loop for now


Example 2:
the first 8 lines are the same as the first 8 lines of the first example, in fact they will not change for any of the other projects, so

#define data 2
#define clock 3

void setup()
{
  pinMode(clock, OUTPUT); // make the clock pin an output
  pinMode(data , OUTPUT); // make the data pin an output


But now in void setup there is an 8 count for loop, its taking an empty byte and shifting 1 bit in at a time starting from the leftmost bit and moving right. This is backwards from the first example where we started from the rightmost bit and worked left, but using MSBFIRST the shift out function sends the data the correct way

Also we add a delay in the for loop so it slows down enough to be visible.

  for(int i = 0; i < 8; ++i) //for 0 - 7 do
  {
    shiftOut(data, clock, MSBFIRST, 1 << i); // bit shift a logic high (1) value by i
    delay(100); // delay 100ms or you would not be able to see it
  }
   
}

void loop(){} // empty loop for now


upload the script and you should now see the bargraph light up each light one at a time

 

« Previous StepDownload PDFView All StepsNext Step »
3 comments
Jan 1, 2012. 7:56 AMNasmi says:
How can I open the file .tmp in arduino IDE ? it seems doesnt work.
thank you :)
Jan 1, 2012. 7:01 PMNasmi says:
Okay .. i'll try .. Thanks !

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
57
Followers
13
Author:osgeld