I have an issue with some code.
When I try to compile this:
#include <avr/interrupt.h>
#include <string.h>
#define AXIS_X 1
#define AXIS_Y 2
#define AXIS_Z 3
int CUBE_SIZE = 8;
int CUBE_BYTES = 64;
volatile byte 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;
}
void loop()
{
int i,x,y,z;
while (true)
{
effect_planboing(AXIS_Z, 400);
}
}
// Flip the cube 180 degrees along the y axis.
void mirror_y (void)
{
unsigned char buffer[CUBE_SIZE][CUBE_SIZE];
unsigned char x,y,z;
memcpy(buffer, cube, CUBE_BYTES); // copy the current cube into a buffer.
fill(0x00);
for (z=0; z<CUBE_SIZE; z++)
{
for (y=0; y<CUBE_SIZE; y++)
{
for (x=0; x<CUBE_SIZE; x++)
{
if (buffer[z][y] & (0x01 << x))
setvoxel(x,CUBE_SIZE-1-y,z);
}
}
}
}
I get this error:
ledcube8x8x8.cpp: In function 'void mirror_y()':
ledcube8x8x8:87: error: invalid conversion from 'volatile void*' to 'const void*'
ledcube8x8x8:87: error: initializing argument 2 of 'void* memcpy(void*, const void*, size_t)'
Since 'cube' and 'current_layer' are also used and modified in the ISR they need to be volatile.
If I ommit the volatile statement, the sketch compiles just fine..
Any ideas?
TIA,
ReSi