Hey guys, I need your help.
I need to be able to control individual LEDs with a 595 IC without shifting out - I'm having quite a bit of trouble with shifting (coding and logic errors) and so I need to write each piece of code sequentially (which is fine). However, I don't know how to do it. I have 10 LEDs and 2 solenoids and I'm going to be miniaturizing the circuit using an ATTiny, so I absolutely need to use a shift register to reduce the number of pins needed.
I want to be able to write different delay times to each LED and have one LED light up after the other, then the solenoid, and then have the pattern repeat from the other side.
Long story short, is there any way to control an LED without shifting if it's connected to a 595?
If you mean by "shifting", "send out serial data to the 595 every time", then no...
If you mean "using the bit shift operator", yeah. But if that's the simplest code, probably not but he, I'm not writing it!
Aka, clarify "shifting".
If it's still unclear, I want to be able to write something like
digitalWrite (LED1, HIGH);
delay (100);
digitalWrite (LED2, HIGH);
delay (100);
digitalWrite (LED3, HIGH);
delay (100);
digitalWrite (LED4, HIGH);
delay (100);
digitalWrite (LED5, HIGH);
delay (100);
digitalWrite (LED6, HIGH);
delay (100);
digitalWrite (LED7, HIGH);
delay (100);
digitalWrite (LED8, HIGH);
delay (100);
digitalWrite (LED9, HIGH);
delay (100);
digitalWrite (SOLENOID1, HIGH);
digitalWrite (LED10, HIGH);
delay (1000);
digitalWrite (LED9, HIGH);
delay (100);
digitalWrite (LED8, HIGH);
delay (100);
digitalWrite (LED7, HIGH);
delay (100);
digitalWrite (LED6, HIGH);
delay (100);
digitalWrite (LED5, HIGH); delay (100);
digitalWrite (LED4, HIGH);
delay (100);
digitalWrite (LED3, HIGH);
delay (100);
digitalWrite (LED2, HIGH);
delay (100);
digitalWrite (SOLENOID2, HIGH);
digitalWrite (LED1, HIGH);
delay (1000);
and have that in a loop.
I'm okay with shifting it, but I can't get the code to work the way I want it to...
One, you should NEVER write that... NOTHING follows a ;
Second, delay() will make it very hard to do/time multiple things. Might not be a problem if the sequence is really fixed and you don't need to (immediately) react to inputs/.
Third, heard of arrays?
Fourth, heard of arrays?
Fifth, heard of arrays?
And yes and no. You can't use them like digitalWrite() but yeah, you're free to make a function (or class if you want to go fancy) that can follow that same style.
If you want individual control of LEDs, use NeoPixles. They work great, and are very reasonably priced. Best of all, you can control 256 of them with a single digital output.
Regards,
Ray L.
septillion:
One, you should NEVER write that... NOTHING follows a ;
Second, delay() will make it very hard to do/time multiple things. Might not be a problem if the sequence is really fixed and you don't need to (immediately) react to inputs/.
Third, heard of arrays?
Fourth, heard of arrays?
Fifth, heard of arrays?And yes and no. You can't use digitalWrite() but yeah, you're free to make a function (or class if you want to go fancy) that can follow that same style.
I wrote the delay in the same line because I wanted the function of the code to be clear to you. I've edited it to fix the code. ![]()
I've tried a binary array detailing out exactly what i wanted it to do - didn't work.
Also, delay() is fine because I don't have any inputs - this is everything in the project.
Why do you want/need to use a shift register ?
UKHeliBob:
Why do you want/need to use a shift register ?
I'm planning on miniaturizing the project in the future - the shift register would allow me to use an ATTiny.
AnuragKS:
I'm planning on miniaturizing the project in the future - the shift register would allow me to use an ATTiny.
And NeoPixels would allow you to eliminate the shift registers. They require just ONE digital output, and NO external hardware, to individually control up to 256 LEDs. Even RGB LEDs.
Regards,
Ray L.
Hey AnuragKS
Read through this tutorial.
Then take the code from this tutorial.
Modify it slightly and you should be able to rewrite your code from
digitalWrite (LED1, HIGH);
delay (100);
digitalWrite (LED2, HIGH);
...
to
registerWrite(LED1, HIGH);
delay (100);
registerWrite(LED2, HIGH);
...
All it did to get me there was to google "arduino LED 595"
AnuragKS:
I'm planning on miniaturizing the project in the future - the shift register would allow me to use an ATTiny.
You cannot use a shift register without shifting the data into it. The clue is in the name. Either fix the problems that you have been having or use NeoPixels.
Why not post details of the problems that you have been having including the code and any error messages.
Some seem to have missed this:
AnuragKS:
I have 10 LEDs and 2 solenoids...
Yeah, and sometimes you don't want all the RGB mumbo jumbo.
But yeah, if you use a shift register you need to shift out data. But you can make functions to "hide" the shifting in order to make a nicer interface. That's up to your code (or Google :D) skills.