Need Help!!! Ive built my 8x8x8 led cube but i cant for the life of me figure out the programming for it.
I have code for the uno but Im using a mega2560. Could someone please give me some guidance as to how to make it work? I feel like im trying to learn this programming thing backwards.... Thanks!!
attached is the code i have. It was written By CHR on instructables i guess.
Im using these pin's on the Mega2560
30-37 for the Data Bus for latches
50 for output enable
51-52 for address bus for latches
42-49 for layer select
Never come across a cool smilie as a quantity to compare to.
This is why we have rules about posting code. We also have rules which suggest how to ask a question and what information you need to give.
Please read them:- How to use this forum
everything is identical to his except the avr board.
I am using an arduino Mega2560 instead of the UNO and the code given is not compatible because the ports on the microcontrollers are different. Im trying to figure out how to wire my mega board and modify the UNO code to work with each other. I do know that i am trying to write an interrupt routine and use a timer to do it.
I have zero experience with any code written outside of the arduino platform and his code uses the registers directly. Tell me exactly what other information you need and i will gladly give it. Im just afraid that if i go too much further ill just confuse you. I dont speak programming. I have just scratched the surface.
#include <avr/interrupt.h>
#include <string.h>
#include <math.h>
#define AXIS_X 1
#define AXIS_Y 2
#define AXIS_Z 3
int CUBE_SIZE = 8;
volatile unsigned char cube[8][8];
volatile int current_layer = 0;
void setup()
{
int i;
for(i=0; i<54; i++)
pinMode(i, OUTPUT);
// pinMode(A0, OUTPUT) as specified in the arduino reference didn't work. So I accessed the registers directly.
DDRL = 0xff;
PORTL = 0x00;
// Reset any PWM configuration that the arduino may have set up automagically!
TCCR2A = 0x00;
TCCR2B = 0x00;
TCCR2A |= (0x01 << WGM21); // CTC mode. clear counter on TCNT2 == OCR2A
OCR2A = 10; // Interrupt every 25600th cpu cycle (256*100)
TCNT2 = 0x00; // start counting at 0
TCCR2B |= (0x01 << CS22) | (0x01 << CS21); // Start the clock with a 256 prescaler
TIMSK2 |= (0x01 << OCIE2A);
}
ISR (TIMER2_COMPA_vect)
{
int i;
// all layer selects off
PORTL = 0x00;
PORTB &= 0x0f;
PORTB |= 0x08; // output enable off.
for (i=0; i<8; i++)
{
PORTC = cube[current_layer][i];
PORTB = (PORTB & 0xF8) | (0x07 & (i+1));
}
PORTB &= 0b00110111; // Output enable on.
current_layer++;
if (current_layer == 8)
current_layer = 0;
}
Nothing was working and i started grounding my cube and Holy crap its working.....sortve. My transistors are not grounding like they are supposed to do. Is that a code thing or hardware thing?
Im going to do some more troubleshooting and see if my transistors are firing.
again any real help would be awesome. Im pulling my hair out
Unfortunately I don't own a oscilloscope. What I meant though is the pins are not putting out any voltage. I think it has something to do with the code.