NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Project Help and Ideas » Getting started with shift registers
November 14, 2011 by claesz |
Just thought I'd share the home made lib I use whenever I use shift registers. I seem to recall I saw some lib for this on the forum some time back, but now I couldn't find it again. If this is a duplicate I apologize... This is not really of interest to anyone who has been using NK for some time and worked with shift registers before. But I thought I should share it as it might be useful for someone trying out shift registers for the first time. Basically it gives you 3 easy functions to control the shift registers: shiftOutBit(pin, value) - f ex shiftOutBit(7, 1); shiftOutByte(value) - f ex shiftOutByte(0b00110011); shiftLatch() to update the shift reg after changes so to turn on every second pin you would shiftOutByte(0b10101010); shiftLatch(); and then to turn on pin 4 you would do (pin 4 would be 3 in the array (0-7 = 8)) shiftOutBit(3,1); shiftLatch(); or you could update many values in one go shiftPin[1] = 1; shiftPin[2] = 1; shiftPin[3]; shiftOutBit(1,1); // We need to pass a pin value to update the whole array, so we pass pin 1 again. shiftLatch(); Not very exciting stuff, I know, but perhaps of some use if you want an easy way of integrating shift regs with their NK projects.
Here is an example using the lib:
|
---|---|
November 14, 2011 by hevans (NerdKits Staff) |
Hi calesz, Thanks for posting this. It should help folks who are new to using shift registers. It might be helpful if you posted a Library article about your code, that way it easier to find in the future. Humberto |
November 14, 2011 by claesz |
Thanks! Didn't quite feel it was advanced enough for the "permanent" library so I updated it quickly to handle chained shift regs. I have just tested this quickly, and it seems to work. With two shift regs you would simply do shiftOutBit(7,1); shiftOutBit(15,1); shiftLatch(); to set the last pin of both regs. I'll wait a bit to see if anyone has some comments and if not I'll post it as a library article.
And here a sample code:
|
November 14, 2011 by Ralphxyz |
The nice thing about the Nerdkit Community Library is that it is "like" a wiki. It is the communities responsibility to make sure postings are first quality. If I see something posted that I think should be enhanced then I have the responsibility to enhance it or at the least to make mention of the library article here in the forum. There isn't a specific library discussion forum. Or for that matter even direct attribute, if you post an article then your user name is attributed until I go in and make a spelling correction, then I would be attributed and your atribute would be lost. That is why it truly is a community library like a wiki. So please if you have working code or a working project or even just information you believe to be accurate please post it to the library. I like your shift register code, between that and Rick's shift register postings I've gotten a good handle on shift register operations. It would be good to have them consolidated or posted in parallel in the library so they both would be at hand. Possible you are making certain assumptions about people's understanding of coding syntax so you might want to consider what level of programing skills you assume the average reader has but post what you have "that works". Ralph |
November 15, 2011 by claesz |
I'll have a look at Rick's code and either post it together with my lib, or if he doesn't mind, borrow a bit of the code and make a single lib. I know I am neither very good at commenting my code nor laying it out in a logical way. My preparation for each project before I start typing code usually consist of two cups of espresso. It may not be as professional as starting with a pen and paper draft, but it does have the advantage of waking me up. |
Please log in to post a reply.
Did you know that many systems in nature can be described by a first order response? Learn more...
|