arduino programming question

hi. im trying to build a led cube 4x4x4 for starters to learn about how this things work. im making it with shift registers and an arduino uno.

im sorry if i am bad at explaining myself, im making each layer with 4x transistors on cathode and 4x transistors on anode. each transistor is going to be controlled by shift registers.(74hc575)

so in my code (i dont know if you can see it) i use the shiftOuf function. and the way i have written it now is int led1 = 0x01; //00000001(binary notation)
and so on. so when i need to use the led1 i will need to write

//ground latchPin and hold low for as long as you are transmitting
digitalWrite(latchPin, 0);
//move 'em out
shiftOut(dataPin, clockPin, MSBFIRST, led1 );
//return the latch pin high to signal chip that it
//no longer needs to listen for information
digitalWrite(latchPin, 1);
delay(300);

is it possible to make a function of this so i can just write: eksample : led1,ledA
? could not find any info i could wrap my head around so any help would be appreciated.

thanks in advance

  • Markus

markus_test.ino (12.2 KB)

Hi,

Welcome to the forum.

Can you please post a copy of your sketch, using code tags?
They are made with the </> icon in the reply Menu.
See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

That way well will be able to give you good answers.

Thanks… Tom… :slight_smile:

//Pin connected to ST_CP of 74HC595
int latchPin = 8;
//Pin connected to SH_CP of 74HC595
int clockPin = 12;
////Pin connected to DS of 74HC595
int dataPin = 11;


void setup() {
  //set pins to output because they are addressed in the main loop
  pinMode(latchPin, OUTPUT);
  Serial.begin(9600);

}
void loop()
 {
     {//binary notation as comment led LAYER 1 and 3
      //anodes
     int led1 = 0x01; //00000001
     int led2 = 0x02; //00000010
     int led3 = 0x04; //00000100
     int led4 = 0x08; //00001000
      //cathodes
     int ledA = 0x01; //00000001
     int ledB = 0x02; //00000010
     int ledC = 0x04; //00000100
     int ledD = 0x08; //00001000

      //layer 2 and 4
      //anodes
     int led5 = 0x10; // 00010000
     int led6 = 0x20; // 00100000
     int led7 = 0x40; // 01000000
     int led8 = 0x80; // 10000000
      //cathodes
     int ledE = 0x10; // 00010000
     int ledF = 0x20; // 00100000
     int ledG = 0x40; // 01000000
     int ledH = 0x80; // 10000000 


     
    //ground latchPin and hold low for as long as you are transmitting
    digitalWrite(latchPin, 0);
    //move 'em out
    shiftOut(dataPin, clockPin, MSBFIRST, led1 );
    shiftOut(dataPin, clockPin, MSBFIRST, ledA );
    shiftOut(dataPin, clockPin, MSBFIRST, led5 );
    shiftOut(dataPin, clockPin, MSBFIRST, ledE );
    //return the latch pin high to signal chip that it
    //no longer needs to listen for information
    digitalWrite(latchPin, 1);
    delay(300);
     {//binary notation as comment led LAYER 1 and 3

Why is that curly brace there?

its one i have forgotten to remove i guess..

the question is, is it possible to get the shiftOut function so that i can just write eks. led1,ledA? and it will shiftOut 0x01; 0x01; ?

its going to be much easier to write than to write the whole shiftOut function every time i want a led to light up..

any help much appreciated :)

The shiftOut() function shifts a whole byte so the answer to your question is no. You can, however, change just the state of 1 bit in a byte and then shift out the whole byte. Would that help ?

I guess not, I will have to think it over. Is there a better way to write a program to controll 64 leds using 4 shift registers(74hc595), and being able to control both the cathode and anode ?

ShiftRegister595 library

http://playground.arduino.cc/Code/ShiftRegister595

would that be of any help ?

dan