Electronic – arduino – 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]={

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);  


Best Answer

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


  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?