So I have a compiler error and I don't know what to do with it. The error is below.
LCDArrayStylesEDIT.ino: In function 'int randomWriteArray2(char (*)[16])':
LCDArrayStylesEDIT:135: error: invalid conversion from 'int*' to 'int'
LCDArrayStylesEDIT:136: error: invalid types 'int [2][int [16]]' for array subscript
This function basically shuffles an array initialized with integers to generate a random pick.
orderCols[][] gets filled with 0 to cols-1, it's shuffled.
orderRows[] gets filled with 0 to rows-1, it's shuffled.
I then iterate over an array with chars called LCDarray[][] to print to the randomized locations by picking elements from LCDarray and placing them in the correct spot on the LCD with the values in the shuffled arrays.
Once orderRows[] is used completely it's reinitialized and shuffled to get more random picks until all cols are printed.
//pertinent declarations
#include <LiquidCrystal.h>
#define cols 16
#define rows 2
char LCDarray[rows][cols];
int randomWriteArray2(char LCDarray[][cols]){
int j=0, k=0, r=0, temp=0;
int orderCols[rows][cols];
int orderRows[rows];
//randomSeed(time);
//fill orderCols with "0 to cols-1" for all rows
for(j=0;j<rows;j++){
for(k=0;k<cols;k++){
orderCols[j][k]=k;
}
}
//randomize orderCols
for(j=0;j<rows;j++){
for (k=0;k<cols;k++){
r=random(cols);//pick random number from 0-cols
temp=orderCols[j][k];//temp of swap area
orderCols[j][k]=orderCols[j][r];//swap in selected number
orderCols[j][r]=temp;//save temp number
}
}
//fill orderRows with "0 to rows-1"
for(k=0;k<rows;k++)orderRows[k]=k;
//randomize elements
for(k=0;k<cols;k++){
r=random(rows);//pick random number from 0-cols
temp=orderRows[k];//temp of swap area
orderRows[k]=orderRows[r];//swap in selected number
orderRows[r]=temp;//save temp number
}
//print by randomizing order rows each time and printing all cells in order
int column,row;//extra variables for temporary readability
for(j=0;j<cols;j++){
for(k=0;k<rows;k++){
column=orderCols[k];
row=orderRows[orderCols[k]][k];
lcd.setCursor(column, row);
lcd.write(LCDarray[row][column]);
delay(100);
}
//rerandomize row pick
for(k=0;k<rows;k++)orderRows[k]=k;
for(k=0;k<cols;k++){
r=random(rows);//pick random number from 0-cols
temp=orderRows[k];//temp of swap area
orderRows[k]=orderRows[r];//swap in selected number
orderRows[r]=temp;//save temp number
}
}
wipeArray(LCDarray);
return 0;
}