Hi,
I am trying to control an RGB strip, and to create some of the effects would like to store the brightness of each RGB leds information in a 2D matrix; 3 rows for colour and 160 (NUM of leds) for the columns. I have tried to write functions to handle shifting and displaying the information in the 2D array, but it seems I need to use pointers (maybe?) which I am not familiar with. So I have a few questions:
-Is an array the best way to handle this sort of information? (I think that it is only using 3*160 = 480 bytes of the 1024 on the ATmega168)
-Can I replace a whole column of an array at a time e.g. Array[0] = Array[1]? (as aposed to modifying each element in a column)
-How can I get pointers to work/fix the error message(s)?
Here is the compile error:
shift_Update_etc.cpp: In function ‘void loop()’:
shift_Update_etc:65: error: invalid conversion from ‘void*’ to ‘byte**’
shift_Update_etc:65: error: initializing argument 1 of ‘void Update(byte**, int)’
shift_Update_etc:65: error: label ‘ColourArray’ used but not defined
#include <FastSPI_LED.h>
//SCK = pin 13. SD = pin 11. Pins 10 and 12 are not used.
#define NUM_LEDS 160
struct CRGB { unsigned char b; unsigned char g; unsigned char r; };
struct CRGB *leds;
#define PIN 4
//---Functions---
//Shift every element in the array by 1 to either the left or the right
void ArrayShift(byte** ColourArray, int N_LEDS, char Direction){
if(Direction == 'R'){
for(int i = N_LEDS - 1; i >= 0; i--){
for(int j =0 ; j < 3; j++){
ColourArray[j][i] = ColourArray[j][i-1];
}
}
}
else{
for(int i = 0; i < N_LEDS - 1; i++){
for(int j = 0; j < 3; j++){
ColourArray[j][i] = ColourArray[j][i-1];
}
}
}
}
//Updates the RGB strip with new information
void Update(byte** ColourArray, int N_LEDS){
memset(leds, 0, NUM_LEDS * 3);
for(int i = 0; i < N_LEDS; i++){
leds[i].r = ColourArray[0][i];
leds[i].g = ColourArray[1][i];
leds[i].b = ColourArray[2][i];
}
delay(1); //Min time needed to write data to strip
FastSPI_LED.show();
}
//---End functions---
void setup()
{
FastSPI_LED.setLeds(NUM_LEDS);
FastSPI_LED.setChipset(CFastSPI_LED::SPI_WS2801);
FastSPI_LED.setPin(PIN);
FastSPI_LED.setDataRate(2); // data rate 2 is good (default is 1)
FastSPI_LED.init();
FastSPI_LED.start();
leds = (struct CRGB*)FastSPI_LED.getRGBData();
memset(leds, 0, NUM_LEDS * 3);
FastSPI_LED.show();
byte ColourArray[3][NUM_LEDS]; //Setup the array
for ( int i = 0; i<NUM_LEDS; i++){
for(int j = 0; j<3; j++){
ColourArray[j][i] = 255;
}
}
}
void loop() {
Update(&&ColourArray, NUM_LEDS);
}