# coding using Arduino, two 74HC595 and two RGB LED, problems with shifting out database

the whole point of this was to be able to send 8 bits of color code to 2 rgb leds through 2 74hc595 registers. if i can get the default color for each led to be sent out then the next part of code is to have a user interface to let someone select which led and what color they want. so now trying to shiftout default colors to these 2 leds. when it compiled i got no shifting leds did not change. like i said i am a noob at this stuff.

#include <arduino.h>
const int ledred = (char)0x80;
const int ledgreen = 0x20;
const int ledcyan = 0x28;
const int ledyellow = (char)0x0A0;
const int ledwhite = (char)0x0A8;
const int ledblack = 0x00;
const int ledvoliet = 0x44;
const int ledblue = 0x08;

#define step1 1
#define step2 2
#define step3 3
#define step4 4
#define step5 5
#define step6 6
#define step7 7
#define step8 8

#define led1 1
#define led2 2
#define led3 3
#define led4 4
#define led5 5
#define led6 6
#define led7 7
#define led8 8

char display_step;
char i;
char c;
char str[80],sstep,lamp,color;
int done;
char colors [8][7]={
"Red   " ,"Green"   ,"Cyan  "   ,"Yellow"  ,"White "  ,"Black "  ,"Voliet"  ,"Blue  "};

char database[56]={
8,ledred,ledgreen,ledcyan,ledyellow,ledblack,ledwhite,
7,ledvoliet,ledblue,ledwhite,ledyellow,ledcyan,ledred,
3,ledred,ledred,ledred,ledblue,ledblue,ledblue,
5,ledred,ledwhite,ledblue,ledred,ledwhite,ledblue,
9,ledgreen,ledblue,ledvoliet,ledyellow,ledcyan,ledblack,
4,ledblack,ledblue,ledblack,ledyellow,ledblack,ledcyan,
6,ledwhite,ledblue,ledgreen,ledvoliet,ledcyan,ledyellow,
10,ledgreen,ledyellow,ledblue,ledred,ledblack,ledblue};

char numberlamps=2;
char numbersteps=8;
const int data = 9;
const int clock = 10;
const int latch = 8;

int main()
{
pinMode(data, OUTPUT);
pinMode(clock, OUTPUT);
pinMode(latch, OUTPUT);
}

void loop(){

int index;
int i;
int updateLEDs;
int lampvalue;

display_step = 1 + display_step%numbersteps;
index = (display_step - 1)*(numberlamps + 1);
time = database[index];
for( i = index +1; i < numberlamps  ; i++);

lampvalue = database[index];
digitalWrite(latch, LOW);
shiftOut(data, clock, MSBFIRST, lampvalue);
digitalWrite(latch, HIGH);

}

• This needs an edit / cleanup, highlight the code blocks and hit the '{}' button – Grady Player Mar 8 '13 at 14:29
• What's the question... the code doesn't even compile without error... what are you trying to do? – vicatcu Mar 8 '13 at 14:38
• Why do you need two shift registers to drive two RGB LEDs? One shift register has eight outputs. Each RGB LED needs three inputs... – vicatcu Mar 8 '13 at 22:48

I suspect this is not the entire code.

1. You can't use delay as a variable name, it's (essentially) a reserved word in Arduino (it's a pre-defined function actually), and anyway you don't use that variable for anything.
2. You need brackets in your include (i.e. #include <arduino.h>)
3. You have a code block (the innermost set of enclosing in braces { ... }) for no apparent reason

UPDATE:

1. You probably shouldn't have a semicolon after for( i = index +1; i < numberlamps ; i++), and you should probably have curly braces around the subsequent lines of code.
2. The line display_step = 1 + display_step%numbersteps; should probably read display_step = (1 + display_step)%numbersteps;
3. You read information into the time variable, but then you don't do anything with that information.
4. A very effective way to diagnose problems with Arduino code like this is to use the Serial Monitor to periodically output relevant variable values as your program executes, using Serial.println(var_name) statements.

The problem is really that your code doesn't make sense and has no comments that express what you think it does... how about you start by drawing and sharing a flow diagram?

• the whole point of this was to be able to send 8 bits of color code to 2 rgb leds through 2 74hc595 registers. if i can get the default color for each led to be sent out then the next part of code is to have a userinterface to let someone select which led and what color they want. so now trying to shiftout default colors to these 2 leds. when it compiled i got no shifting leds did not change. like i said i am a noob at this stuff. – aces1026 Mar 8 '13 at 15:10
• this part of the program is to just keep looking at the steps and lamcode to update the bits that are being shifted out to leds – aces1026 Mar 8 '13 at 15:20

Have you considered maybe going through a tutorial such as LadyAda's Arduino tutorial?

It answers many common questions and problems, so we can spend time fixing new and interesting problems :-).

The biggest problem I see in this code is

int main() // Doesn't work with Arduino -- Arduino has its own internal main().
{
pinMode(data, OUTPUT);
pinMode(clock, OUTPUT);
pinMode(latch, OUTPUT);
}


Since you are using an Arduino, you almost certainly want to replace that with something more like:

void setup() {
pinMode(data, OUTPUT);
pinMode(clock, OUTPUT);
pinMode(latch, OUTPUT);
}


How / where from is loop() called?

A circuit diagram would help as well. There are two additional possible problems: the 74hc595 shift register OE (output enable) pin (pin 13 on in the DIP version) must be LOW in order for the shift register to output anything, while the MR (master reset) pin (pin 10 in the DIP) must be high. You probably want to tie OE to ground and MR to VCC while you are testing.

vicatcu is right that each 74HC595 can in theory drive two leds, as each one has 8 outputs (9 if you count the Q7S line), however, each chip can only drive 70mA max, which means that each of your LED lines will be limited to 11.5mA of current, i.e. not as bright as could be otherwise. Nonetheless, how are the two 74HC595 connected? If you are running the same data, clock, and latch lines to both of them (i.e parallel configuration) then you cannot address them separately.

• loop() is an Arduino thing, the bootstrap calls a function called setup() and then continuously calls loop(). – PeterJ Mar 9 '13 at 3:18
• Oh, right. It has been a while since I've done Arduino. Forgot that main() is hidden away from the user. – angelatlarge Mar 9 '13 at 17:41