The code I'm working on is related to a dual color matrix driver using shiftregister. I coded a few sub-routines for updating the screen and reseting it. But I want to make these sub-routines more compatible for futher projects.
/******************************************************************************
** assign hardware pins to register pins
*******************************************************************************/
const int cathodeScreenPins[8] = {
0,1,2,3,4,5,6,7};
const int greenScreenPins[8] = {
15,14,13,12,11,10,9,8};
const int redScreenPins[8] = {
16,17,18,19,20,21,22,23};
/******************************************************************************
** information
*******************************************************************************/
// 2 dimensional arrays to store led states
int greenScreen[8][8];
int redScreen[8][8];
void setup(){
ResetScreen(greenScreen);
ResetScreen(redScreen);
UpdateScreen(cathodeScreenPins, greenScreenPins, redScreenPins);
}
void loop(){
}
void UpdateScreen(int cathodePins[][8], int greenPins[][8], int redPins[][8]){
for(int thisPin = 0; thisPin < 8; thisPin++){
shifter.setPin(cathodePins[thisPin],HIGH);
shifter.setPin(greenPins[thisPin],LOW);
shifter.setPin(redPins[thisPin],LOW);
}
for(int thisCathode = 0; thisCathode < 8; thisCathode++){
for(int thisAnode = 0; thisAnode < 8; thisAnode++){
boolean greenState = greenScreen[thisCathode][thisAnode];
boolean redState = redScreen[thisCathode][thisAnode];
shifter.setPin(cathodePins[thisCathode],LOW);
shifter.setPin(greenPins[thisAnode],greenState);
shifter.setPin(redPins[thisAnode],redState);
}
shifter.write();
shifter.setPin(cathodePins[thisCathode],HIGH);
}
}
void ResetScreen(int screenToReset[][8]){
for(int i = 0 ;i < 8; i++){
for(int ii = 0 ;ii < 8; ii++){
screenToReset[i][ii] = LOW;
}
}
}
When I compile this code I get the following errors:
tic_tac_toe.ino: In function 'void setup()':
tic_tac_toe:43: error: no matching function for call to 'UpdateScreen(const int [8], const int [8], const int [8])'
tic_tac_toe.ino:19: note: candidates are: void UpdateScreen(int (*)[8], int (*)[8], int (*)[8])
tic_tac_toe.ino:21: note: void UpdateScreen(int (*)[8], int (*)[8], int (*)[8], int (*)[8], int (*)[8])
tic_tac_toe.ino: In function 'void UpdateScreen(int (*)[8], int (*)[8], int (*)[8])':
tic_tac_toe:52: error: invalid conversion from 'int*' to 'int'
tic_tac_toe:52: error: initializing argument 1 of 'void Shifter::setPin(int, boolean)'
tic_tac_toe:53: error: invalid conversion from 'int*' to 'int'
tic_tac_toe:53: error: initializing argument 1 of 'void Shifter::setPin(int, boolean)'
tic_tac_toe:54: error: invalid conversion from 'int*' to 'int'
tic_tac_toe:54: error: initializing argument 1 of 'void Shifter::setPin(int, boolean)'
tic_tac_toe:63: error: invalid conversion from 'int*' to 'int'
tic_tac_toe:63: error: initializing argument 1 of 'void Shifter::setPin(int, boolean)'
tic_tac_toe:64: error: invalid conversion from 'int*' to 'int'
tic_tac_toe:64: error: initializing argument 1 of 'void Shifter::setPin(int, boolean)'
tic_tac_toe:65: error: invalid conversion from 'int*' to 'int'
tic_tac_toe:65: error: initializing argument 1 of 'void Shifter::setPin(int, boolean)'
tic_tac_toe:68: error: invalid conversion from 'int*' to 'int'
tic_tac_toe:68: error: initializing argument 1 of 'void Shifter::setPin(int, boolean)'
MatrixControl.ino: In function 'void UpdateScreen(int (*)[8], int (*)[8], int (*)[8], int (*)[8], int (*)[8])':
MatrixControl:126: error: invalid conversion from 'int*' to 'int'
MatrixControl:126: error: initializing argument 1 of 'void Shifter::setPin(int, boolean)'
MatrixControl:127: error: invalid conversion from 'int*' to 'int'
MatrixControl:127: error: initializing argument 1 of 'void Shifter::setPin(int, boolean)'
MatrixControl:128: error: invalid conversion from 'int*' to 'int'
MatrixControl:128: error: initializing argument 1 of 'void Shifter::setPin(int, boolean)'
MatrixControl:137: error: invalid conversion from 'int*' to 'int'
MatrixControl:137: error: initializing argument 1 of 'void Shifter::setPin(int, boolean)'
MatrixControl:138: error: invalid conversion from 'int*' to 'int'
MatrixControl:138: error: initializing argument 1 of 'void Shifter::setPin(int, boolean)'
MatrixControl:139: error: invalid conversion from 'int*' to 'int'
MatrixControl:139: error: initializing argument 1 of 'void Shifter::setPin(int, boolean)'
MatrixControl:142: error: invalid conversion from 'int*' to 'int'
MatrixControl:142: error: initializing argument 1 of 'void Shifter::setPin(int, boolean)'
Full code:
/******************************************************************************
** include libraries
*******************************************************************************/
#include <Shifter.h>
/******************************************************************************
** set register parameters
*******************************************************************************/
#define SER_Pin 4 // 14 SER_IN
#define RCLK_Pin 3 // 12 L_CLOCK
#define SRCLK_Pin 2 // 11 CLOCK
#define randomInput A0
#define NUM_REGISTERS 3 // how many registers are in the chain
//initaize shifter using the Shifter library
Shifter shifter(SER_Pin, RCLK_Pin, SRCLK_Pin, NUM_REGISTERS);
/******************************************************************************
** assign hardware pins to register pins
*******************************************************************************/
const int cathodeScreenPins[8] = {
0,1,2,3,4,5,6,7};
const int greenScreenPins[8] = {
15,14,13,12,11,10,9,8};
const int redScreenPins[8] = {
16,17,18,19,20,21,22,23};
/******************************************************************************
** information
*******************************************************************************/
// 2 dimensional arrays to store led states
int greenScreen[8][8];
int redScreen[8][8];
/******************************************************************************
** global variables
*******************************************************************************/
void setup(){
ResetScreen(greenScreen);
ResetScreen(redScreen);
UpdateScreen(cathodeScreenPins, greenScreenPins, redScreenPins);
}
void loop(){
}
void UpdateScreen(int cathodePins[][8], int greenPins[][8], int redPins[][8]){
for(int thisPin = 0; thisPin < 8; thisPin++){
shifter.setPin(cathodePins[thisPin],HIGH);
shifter.setPin(greenPins[thisPin],LOW);
shifter.setPin(redPins[thisPin],LOW);
}
for(int thisCathode = 0; thisCathode < 8; thisCathode++){
for(int thisAnode = 0; thisAnode < 8; thisAnode++){
boolean greenState = greenScreen[thisCathode][thisAnode];
boolean redState = redScreen[thisCathode][thisAnode];
shifter.setPin(cathodePins[thisCathode],LOW);
shifter.setPin(greenPins[thisAnode],greenState);
shifter.setPin(redPins[thisAnode],redState);
}
shifter.write();
shifter.setPin(cathodePins[thisCathode],HIGH);
}
}
void ResetScreen(int screenToReset[][8]){
for(int i = 0 ;i < 8; i++){
for(int ii = 0 ;ii < 8; ii++){
screenToReset[i][ii] = LOW;
}
}
}
Does anyone have an idea to resolve my problem?
Thanks.