Hi everybody!
A few weeks ago i finished a LED CUBE (the one 8x8x8 LED Cube Kit Introduction | PyroElectro - News, Projects & Tutorials), and it worked flawlessly. But now i need to change the Arduino UNO inside it to an Arduino MEGA. I reconnected each pin on the place it is supposed to be (the same spots as in the ARDUINO UNO) but now the code doesnt work. THe cube recieves power and the status LEDs are lighting up, but no LEDs from the cube responds. I thought Arduino UNO and MEGA used the same language. Why it isn't working?
Please help!
This is the part i think i need to change:
#include <avr/interrupt.h>
#include <string.h>
#define AXIS_X 1
#define AXIS_Y 2
#define AXIS_Z 3
volatile unsigned char cube[8][8];
volatile int current_layer = 0;
void setup()
{
int i;
for(i=0; i<14; i++)
pinMode(i, OUTPUT);
// pinMode(A0, OUTPUT) as specified in the arduino reference didn't work. So I accessed the registers directly.
DDRC = 0xff;
PORTC = 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
PORTC = 0x00;
PORTB &= 0x0f;
PORTB |= 0x08; // output enable off.
for (i=0; i<8; i++)
{
PORTD = cube[current_layer][i];
PORTB = (PORTB & 0xF8) | (0x07 & (i+1));
}
PORTB &= 0b00110111; // Output enable on.
if (current_layer < 6)
{
PORTC = (0x01 << current_layer);
} else if (current_layer == 6)
{
digitalWrite(12, HIGH);
} else
{
digitalWrite(13, HIGH);
}
current_layer++;
if (current_layer == 8)
current_layer = 0;
}
PD: This is the code i used on the previous ARDUINO Uno, and now uploaded to the ARduino MEGA.
http://www.pyroelectro.com/projects/8x8x8_led_cube/pyroelectro_8x8x8.pde
PD2: Everything is connected the same way as before, but on an Arduino MEGA.