In my project there are 20 4 pin RGB LED. i'm using an Arduino UNO and som 74HC595 shift registers. I've tried to put a basic binary counter on the thing but only one color (not one led) of the structure turned on. Can someone explain me why? And if is possible: the idea is to make the led to assume a color and keep it. If someone can help me making the code, it would be great!
The red-green striped wire goes into the 3rd socket, and add a ";" at the end of line 23.
You do not have any red-green striped wires? Your program has no line 23?
I have the same problem with your question. I do not know if you have a bad program or a bad circuit. Read http://arduino.cc/forum/index.php/topic,148850.0.html in particular points 7 thru 11.
So, I'm going to explain:
My idea was to put 20 RGB LEDs on a structure and then with the program i'll set the colors(4): i've followed the shiftout tutorial, but, instead of 2 74HC595 i've got 8 of them. For the program I need total guidance because i don't know to send simple static informations to the shift register, if you or someone else could make a simple example, you gonna give me a very big hint. The wiring is simple: from the arduino to the shift register is the same as this
for the data pins of the shift register then goes in 220 ohm resistor(1 for each pin) and from the resistor to the anode color pin on the LED, while the common goes to a basic ground.
I don't know if this will help any:
Also keep an eye on the maximum current you can draw from the '595.
First,
DO NOT install the cap on the control signal as shown. You should only have a 100nF/0.1uF cap from the Vcc pin to Gnd.
Then, daisy chain your shift registers as shown in the 2nd set of diagrams.
All devices have their SRCLK and SRCK pins wired in parallel.
To send data out, assuming you are storing the state of the LEDs in an array:
byte dataArray[] = {B10010010, B01001001, B00100100, B10010010, B01001001, B00100100, B10010010, B01000000,} // turn on Red left of all devices
Then send the data out when you want to change something, for example oif time based:
// time for an update?
currentMilllis - millis();
if ( ( (currentMillis - previousMillis)>= duration) || updateFlag == 1){ // could also check for a 'flag' here, set from a button read or a maybe serial message being received that led to dataArray being updated
previousMIllis = previousMillis + duration; // set up for next time check if used
updateFlag = 0; // clear the flag if used
for (x=0; x<8; x=x+1){ // EDIT fixed: x=0
shiftOut(dataPin, clockPin, MSBFIRST, dataArray[x] ); // send out the data bytes
}
}
// otherwise keep doing other stuff, and update dataArray when something changes
Note that 20 RGB LEDs need 60 control pins, so the last byye has some unused bits.
With 220 ohm for all LEDs, you may see uneven perceiverd brightnesses.
Red LEDs usually ave around 2.5V drop, 220 would yield around 11mA.
Green, Blue are usually around 3.3V drop, 220 would yield around 7.7mA.
74HC595 is also only rated for just 70mA total current dissipation, so a part with 3 Reds drawing 33mA and 5 Green/Blues drawing 38.5mA = 71.5mA is right at the limit of what can be supported.
You may download my code from here: http://coolarduino.wordpress.com/2012/06/21/tears-of-rainbow/
There are 9 shift registers, but you could figure out how to adjust it from the comments
Be sure to connect MSTCLR to +5, and OE/ (maybe called G) to Gnd or to a PWM pin if you want to fade brightness up & down:
analogWrite (OEpin, 0); //for max brightness (full on)
analogWrite (OEpin, 255); // for max dimming (full off)
with values in the middle for different levels, which may not be perceived linearly or evenly between the colors.
Speaking of LEDs; Should I raise the resistor for avoid damaging the 74HC595? There is an optimal resistance of every single color on the LED? If yes, can someone tell me which are values?
Another problem;
I'm using now only 1 74HC595 and this code
int latchPin = 8;
int clockPin = 12;
int dataPin = 11;
byte dataArray[] = {B10010010, B01001001, B00100100, B10010010, B01001001, B00100100, B10010010, B01000000,};
void setup() {
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void loop() {
for(x=x, x<8, x++){
shiftOut(dataPin, clockPin, MSBFIRST, dataArray[x] ); // send out the data bytes
}
and as result i've got "'x' was not declared in this scope". How to fix this?
replace for(x=x, x<8, x++){
with
for(int x=0; x<8; x++){
Purely for the purposes of testing you might want to include a short delay in your for loop otherwise it will run so fast you won't be able to tell what's happening!
Thanks, but now i have another problem:
while using this code as test
int latchPin = 8;
int clockPin = 12;
int dataPin = 11;
void setup() {
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void loop() {
for (int numberToDisplay = 0; numberToDisplay < 512; numberToDisplay++) {
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay);
digitalWrite(latchPin, HIGH);
delay(500);
}
}
using 2 74HC595, 5 LEDs . they work in 2 groups of 3, sharing the last and the fisrt LED, but the work at the same time
Try this to break up the LEDs.
int latchPin = 8;
int clockPin = 12;
int dataPin = 11;
int numberToDisplay; // moved this to make it obvious that some thought has to go into the coding process
void setup() {
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void loop() {
for (numberToDisplay = 0; numberToDisplay < 512; numberToDisplay++) {
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, highByte(numberToDisplay) ); // highByte - left 8 bits
shiftOut(dataPin, clockPin, MSBFIRST, lowByte(numberToDisplay) ); // lowByte - right 8 bits
digitalWrite(latchPin, HIGH);
delay(500);
}
}