Hello,
I'm making a library for driving a 8x8 bi-colour LED Matrix. The matrix is hooked on the arduino using three 74HC595 shift registers. Problem is I can't pass the variable to my library.
Matrix.h
/*
Matrix.cpp - Library for driving a led matrix.
Created by Glenn Kerselaers, Februari 6, 2014.
Released into the public domain.
*/
#ifndef Matrix_h
#define Matrix_h
#include "Arduino.h"
#include <FrequencyTimer2.h>
#include <Shifter.h>
class Shifter;
class FrequencyTimer2;
class Matrix
{
public:
Matrix(int cathodePins[8], int greenPins[8], int redPins[8], int greenScreen[][8], int redScreen[][8]);
void clear();
void display();
void writeGreen(int,int,int);
void writeRed(int,int,int);
private:
int _cathodePins[8];
int _greenPins[8];
int _redPins[8];
int _greenScreen[][8];
int _redScreen[][8];
};
#endif
Matrix.cpp
/*
Matrix.cpp - Library for driving a led matrix.
Created by Glenn Kerselaers, Februari 6, 2014.
Released into the public domain.
*/
#include <FrequencyTimer2.h>
#include <Shifter.h>
#include "Arduino.h"
#include "Morse.h"
Matrix::Matrix(int cathodePins[8], int greenPins[8], int redPins[8], int greenScreen[][8], int redScreen[][8])
{
for(int i = 0; i < 8; i++){
shifter.setPin(cathodePins[i], LOW);
shifter.setPin(greenPins[i], LOW);
shifter.setPin(redPins[i], LOW);
}
Matrix::clear();
FrequencyTimer2::disable();
FrequencyTimer2::setPeriod(2000);
FrequencyTimer2::setOnOverflow(Matrix::display);
_cathodePins = cathodePins;
_greenPins = greenPins;
_redPins = redPins;
_greenScreen = greenScreen;
_redScreen = redScreen;
}
void Matrix::writeGreen(int x, int y, boolean value){
_greenScreen[x][y] = value;
}
void Matrix:writeRed(int x, int y, boolean value){
_redScreen[x][y] = value;
}
void Matrix::clear(){
for(int i = 0; i < 8; i++){
for(int ii = 0; ii < 8; ii++){
_greenScreen[i][ii] = 0;
_redScreen[i][ii] = 0;
}
}
}
void Matrix::display(){
for(int row = 0; row < 8; row++){
shifter.setPin(_cathodePins[row], LOW);
for(int col = 0; col < 8; col++){
shifter.setPin(_greenPins[col], _greenScreen[col][row]);
shifter.setPin(_redPins[col] , _redScreen[col][row]);
}
shifter.write();
shifter.setPin(_cathodePins[row], HIGH);
}
}
Example code
#include <Matrix.h>
#include <FrequencyTimer2.h>
#include <Shifter.h>
#define SER_Pin 4 // 14 SER_IN
#define RCLK_Pin 3 // 12 L_CLOCK
#define SRCLK_Pin 2 // 11 CLOCK
#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);
const int CATHODEPINS[8] = {
4,5,6,7,0,1,2,3};
const int GREENPINS[8] = {
19,18,17,16, 23,22,21,20};
const int REDPINS[8] = {
12,13,14,15,8,9,10,11};
int GREENSCREEN[8][8];
int REDSCREEN[8][8];
Matrix matrix(CATHODEPINS,GREENPINS,REDPINS,GREENSCREEN,REDSCREEN);
void setup(){
}
void loop(){
writeGreen(0,0,1);
writeRed(7,7,1);
}
Compile error
Example_Matrix:22: error: invalid conversion from 'const int*' to 'int*'
Example_Matrix:22: error: initializing argument 1 of 'Matrix::Matrix(int*, int*, int*, int (*)[8], int (*)[8])'
Example_Matrix:22: error: invalid conversion from 'const int*' to 'int*'
Example_Matrix:22: error: initializing argument 2 of 'Matrix::Matrix(int*, int*, int*, int (*)[8], int (*)[8])'
Example_Matrix:22: error: invalid conversion from 'const int*' to 'int*'
Example_Matrix:22: error: initializing argument 3 of 'Matrix::Matrix(int*, int*, int*, int (*)[8], int (*)[8])'
Example_Matrix.ino: In function 'void loop()':
Example_Matrix:28: error: 'writeGreen' was not declared in this scope
Example_Matrix:29: error: 'writeRed' was not declared in this scope