Show Posts
Pages: [1]
1  Using Arduino / LEDs and Multiplexing / Re: 8x8x8 cube code help on: January 25, 2013, 02:10:33 pm
thank you,

But I think someone wrote a code ready for a 8x8x8.

The cube is only turning on one layer at the time right? so it the 595 should be ok.
2  Using Arduino / LEDs and Multiplexing / 8x8x8 cube code help on: January 25, 2013, 11:21:25 am
Hi all,

I build a 4x4x4 cube and it worked smiley
For a 4x4x4 cube you dont need shifters. So the code is quite easy.

To make a certain shape i just added the following.
B0001,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,10,

Where each led is represented by a 0 or 1 and the last number is the time this shape stays on.

Now I want to build a bigger 8x8x8 cube.
For this i will need shifters and more. On this part I dont need help cause I found enough information online.

But the code is an other part.
I want the same simple way of writing shapes. Now before i found a thread once on someone doing this. But I searched and searched but cant seem to find it anymore.

Can someone show me this thread or maybe they have code to do this ?

Thanks all
3  Using Arduino / Project Guidance / Re: 4x4x4 led cube problem on: December 28, 2012, 07:09:28 am
From the code you posted:

Code:
       // turn previous plane off
        if (plane==0) {
          digitalWrite( PlanePin[CUBESIZE-1], HIGH );
        }
        else {
          digitalWrite( PlanePin[plane-1], HIGH );
        }

...
        // turn current plane on
        digitalWrite( PlanePin[plane], LOW );

I think that code is wrong. If you are driving the planes through a ULN2803 buffer (or through NPN transistors), then the plane outputs are active high, not active low. So you need to write LOW to switch a plane off and HIGH to switch it on.

Thank you very very much it works now!!

The last part of the code should have been as below

Thank you again  smiley-grin smiley-mr-green smiley-grin smiley-mr-green

Code:
// loop while DisplayTime>0 and current time < EndTime
while ( millis() < EndTime ) {
patbufidx = 0; // reset index counter to beginning of buffer
// loop over planes
for (plane=0; plane<CUBESIZE; plane++) {
// turn previous plane off
if (plane==0) {
digitalWrite( PlanePin[CUBESIZE-1], LOW );
} else {
digitalWrite( PlanePin[plane-1], LOW );
}

// load current plane pattern data into ports
ledpin = 0;
for (ledrow=0; ledrow<CUBESIZE; ledrow++) {
for (ledcol=0; ledcol<CUBESIZE; ledcol++) {
digitalWrite( LEDPin[ledpin++], PatternBuf[patbufidx] & (1 << ledcol) );
}
patbufidx++;
}

// turn current plane on
digitalWrite( PlanePin[plane], HIGH );
// delay PLANETIME us
delayMicroseconds( PLANETIME );
} // for plane
} // while <EndTime
} while (DisplayTime > 0); // read patterns until time=0 which signals end
}
4  Using Arduino / Project Guidance / Re: 4x4x4 led cube problem on: December 27, 2012, 01:11:28 pm
thanks for your reply.

When i control the leds iduvidual by saying turn on layer 3 and led 6 it works.

5  Using Arduino / Project Guidance / Re: 4x4x4 led cube problem on: December 27, 2012, 11:15:58 am
can no one help me ?
6  Using Arduino / Project Guidance / Re: 4x4x4 led cube problem on: December 25, 2012, 05:46:52 am
No you only need 2. The idea is you light one column and one plane. This will cause one led to light up. Cause the other leds in the column are not grounded by the plane.
To light several leds is to switch very fast between them (called multiplexing).

the code is not mine i just changed a bit.
Does anyone see where I can change the number of refresh time?

7  Using Arduino / Project Guidance / Re: 4x4x4 led cube problem on: December 24, 2012, 05:34:57 pm
I only made  the part where i light up one led to check if it works. When i run this code a whole column lights up.

the code below is my part. the rest I copied of the instructables
 B1000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,100,

Code:
#include <avr/pgmspace.h> // allows use of PROGMEM to store patterns in flash

#define CUBESIZE 4
#define PLANESIZE CUBESIZE*CUBESIZE
#define PLANETIME 500 // time each plane is displayed in us -> 100 Hz refresh
#define TIMECONST 20 // multiplies DisplayTime to get ms - why not =100?

// LED Pattern Table in PROGMEM - last column is display time in 100ms units
// TODO this could be a lot more compact but not with binary pattern representation
prog_uchar PROGMEM PatternTable[] = {
  // blink on and off

  B1000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,100,

  B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,10,

  // this is a dummy element for end of table (duration=0) aka !!!DO NOT TOUCH!!!
  B0000, B0000, B0000, B0000, B0000, B0000, B0000, B0000, B0000, B0000, B0000, B0000, B0000, B0000, B0000, B0000, 0
};

/*
** Defining pins in array makes it easier to rearrange how cube is wired
 ** Adjust numbers here until LEDs flash in order - L to R, T to B
 ** Note that analog inputs 0-5 are also digital outputs 14-19!
 ** Pin DigitalOut0 (serial RX) and AnalogIn5 are left open for future apps
 */

int LEDPin[] = {
  13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 14, 15};
int PlanePin[] = {
  16, 17, 18, 19};

// initialization
void setup()
{
  int pin; // loop counter
  // set up LED pins as output (active HIGH)
  for (pin=0; pin<PLANESIZE; pin++) {
    pinMode( LEDPin[pin], OUTPUT );
  }
  // set up plane pins as outputs (active LOW)
  for (pin=0; pin<CUBESIZE; pin++) {
    pinMode( PlanePin[pin], OUTPUT );
  }
}

// display pattern in table until DisplayTime is zero (then repeat)
void loop()
{
  // declare variables
  byte PatternBuf[PLANESIZE]; // saves current pattern from PatternTable
  int PatternIdx;
  byte DisplayTime; // time*100ms to display pattern
  unsigned long EndTime;
  int plane; // loop counter for cube refresh
  int patbufidx; // indexes which byte from pattern buffer
  int ledrow; // counts LEDs in refresh loop
  int ledcol; // counts LEDs in refresh loop
  int ledpin; // counts LEDs in refresh loop

  // Initialize PatternIdx to beginning of pattern table
  PatternIdx = 0;
  // loop over entries in pattern table - while DisplayTime>0
  do {
    // read pattern from PROGMEM and save in array
    memcpy_P( PatternBuf, PatternTable+PatternIdx, PLANESIZE );
    PatternIdx += PLANESIZE;
    // read DisplayTime from PROGMEM and increment index
    DisplayTime = pgm_read_byte_near( PatternTable + PatternIdx++ );
    // compute EndTime from current time (ms) and DisplayTime
    EndTime = millis() + ((unsigned long) DisplayTime) * TIMECONST;

    // loop while DisplayTime>0 and current time < EndTime
    while ( millis() < EndTime ) {
      patbufidx = 0; // reset index counter to beginning of buffer
      // loop over planes
      for (plane=0; plane<CUBESIZE; plane++) {
        // turn previous plane off
        if (plane==0) {
          digitalWrite( PlanePin[CUBESIZE-1], HIGH );
        }
        else {
          digitalWrite( PlanePin[plane-1], HIGH );
        }

        // load current plane pattern data into ports
        ledpin = 0;
        for (ledrow=0; ledrow<CUBESIZE; ledrow++) {
          for (ledcol=0; ledcol<CUBESIZE; ledcol++) {
            digitalWrite( LEDPin[ledpin++], PatternBuf[patbufidx] & (1 << ledcol) );
          }
          patbufidx++;
        }

        // turn current plane on
        digitalWrite( PlanePin[plane], LOW );
        // delay PLANETIME us
        delayMicroseconds( PLANETIME );
      } // for plane
    } // while <EndTime
  }
  while (DisplayTime > 0); // read patterns until time=0 which signals end
}
8  Using Arduino / Project Guidance / Re: 4x4x4 led cube problem on: December 24, 2012, 05:16:39 pm
nobody?
9  Using Arduino / Project Guidance / 4x4x4 led cube problem on: December 24, 2012, 02:31:04 pm
Hi all,

I am using Arduino to become more electronicly savy as a mechanical engineer. So I am pretty much a noob.

I build a 4x4x4 cube following the example in the link below.
http://www.instructables.com/id/4x4x4-LED-Cube-Arduino/#intro

One thing i did different, because I dont have the NPN transistors. I used a Darlington transitor array uln2803A.

Now I want to write some of my own code.
But when I just want to light up one led the whole collum lights up. What am I doing wrong??



The code is below.
Code:
#include <avr/pgmspace.h> // allows use of PROGMEM to store patterns in flash

#define CUBESIZE 4
#define PLANESIZE CUBESIZE*CUBESIZE
#define PLANETIME 500 // time each plane is displayed in us -> 100 Hz refresh
#define TIMECONST 20 // multiplies DisplayTime to get ms - why not =100?

// LED Pattern Table in PROGMEM - last column is display time in 100ms units
// TODO this could be a lot more compact but not with binary pattern representation
prog_uchar PROGMEM PatternTable[] = {
// blink on and off

B1000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,100,

B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,10,

// this is a dummy element for end of table (duration=0) aka !!!DO NOT TOUCH!!!
B0000, B0000, B0000, B0000, B0000, B0000, B0000, B0000, B0000, B0000, B0000, B0000, B0000, B0000, B0000, B0000, 0
};

/*
** Defining pins in array makes it easier to rearrange how cube is wired
** Adjust numbers here until LEDs flash in order - L to R, T to B
** Note that analog inputs 0-5 are also digital outputs 14-19!
** Pin DigitalOut0 (serial RX) and AnalogIn5 are left open for future apps
*/

int LEDPin[] = {13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 14, 15};
int PlanePin[] = {16, 17, 18, 19};

// initialization
void setup()
{
int pin; // loop counter
// set up LED pins as output (active HIGH)
for (pin=0; pin<PLANESIZE; pin++) {
pinMode( LEDPin[pin], OUTPUT );
}
// set up plane pins as outputs (active LOW)
for (pin=0; pin<CUBESIZE; pin++) {
pinMode( PlanePin[pin], OUTPUT );
}
}

// display pattern in table until DisplayTime is zero (then repeat)
void loop()
{
// declare variables
byte PatternBuf[PLANESIZE]; // saves current pattern from PatternTable
int PatternIdx;
byte DisplayTime; // time*100ms to display pattern
unsigned long EndTime;
int plane; // loop counter for cube refresh
int patbufidx; // indexes which byte from pattern buffer
int ledrow; // counts LEDs in refresh loop
int ledcol; // counts LEDs in refresh loop
int ledpin; // counts LEDs in refresh loop

// Initialize PatternIdx to beginning of pattern table
PatternIdx = 0;
// loop over entries in pattern table - while DisplayTime>0
do {
// read pattern from PROGMEM and save in array
memcpy_P( PatternBuf, PatternTable+PatternIdx, PLANESIZE );
PatternIdx += PLANESIZE;
// read DisplayTime from PROGMEM and increment index
DisplayTime = pgm_read_byte_near( PatternTable + PatternIdx++ );
// compute EndTime from current time (ms) and DisplayTime
EndTime = millis() + ((unsigned long) DisplayTime) * TIMECONST;

// loop while DisplayTime>0 and current time < EndTime
while ( millis() < EndTime ) {
patbufidx = 0; // reset index counter to beginning of buffer
// loop over planes
for (plane=0; plane<CUBESIZE; plane++) {
// turn previous plane off
if (plane==0) {
digitalWrite( PlanePin[CUBESIZE-1], HIGH );
} else {
digitalWrite( PlanePin[plane-1], HIGH );
}

// load current plane pattern data into ports
ledpin = 0;
for (ledrow=0; ledrow<CUBESIZE; ledrow++) {
for (ledcol=0; ledcol<CUBESIZE; ledcol++) {
digitalWrite( LEDPin[ledpin++], PatternBuf[patbufidx] & (1 << ledcol) );
}
patbufidx++;
}

// turn current plane on
digitalWrite( PlanePin[plane], LOW );
// delay PLANETIME us
delayMicroseconds( PLANETIME );
} // for plane
} // while <EndTime
} while (DisplayTime > 0); // read patterns until time=0 which signals end
}

10  Using Arduino / Programming Questions / 2x2x2 cube qeustion on: November 24, 2012, 10:14:55 am
Hi all,

I am new to arduino and as a first try i made a led ube 2x2x2.
I connected the annodes to I/O 13,12,11,10 and the 2 kathodes to 4 and 5.

If i run a simple program and try to light all the leds only one layer will go on.
Why wont both layers go on?

I used no resistors.

My code below

//2x2x2 LED Cube Sequence 1
//By: TT
//23-11-2012
//all lights on/off
int C1 = 13;
int C2 = 12;
int C3 = 11;
int C4 = 10;

int L1 = 3;
int L2 = 4;


void setup() {
  pinMode(C1, OUTPUT);
  pinMode(C2, OUTPUT);
  pinMode(C3, OUTPUT);
  pinMode(C4, OUTPUT);

  pinMode(L1, OUTPUT);
  pinMode(L2, OUTPUT);

}

void loop() {
  digitalWrite(L1, HIGH); //Layer 1 on
  digitalWrite(L2, HIGH); //Layer 2 on
  digitalWrite(C1, HIGH);
  delay(50);
  digitalWrite(C2, HIGH);
  delay(50);
  digitalWrite(C3, HIGH);
  delay(50);
  digitalWrite(C4, HIGH);
  delay(500);
  digitalWrite(C4, LOW);
  digitalWrite(L1, LOW); //Layer 1 Ends
  digitalWrite(C1, LOW);
  digitalWrite(C2, LOW);
  digitalWrite(C3, LOW);
  digitalWrite(L2, LOW); //Layer 2 Ends
 
}
Pages: [1]