From fb82d0c1c53ba090ba975604c635f058addf91a4 Mon Sep 17 00:00:00 2001 From: Electro707 Date: Sun, 11 Oct 2020 16:49:06 -0400 Subject: [PATCH] Mainly bug fix for the setPixel function with some internal improvements --- CHANGELOG | 5 ++++ examples/ScanPixels/ScanPixels.ino | 13 +++------ extra/Doxyfile | 2 +- keywords.txt | 1 + library.properties | 2 +- src/simple_matrix.cpp | 45 +++++++++++++++++++++--------- src/simple_matrix.h | 16 +++++++---- 7 files changed, 54 insertions(+), 30 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 2ff869d..d7c7656 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,8 @@ +v1.4.1 + -Fixed a bug where the setPixel function didn't have a function definition + -Added a clearPixel function + -Improved interal programming (mainly for the sendMatrixBuffer function) + -Changed the ScanPixels example to use the clearPixel and setPixel functions v1.4 -Added support for any size LED matrix -Added option for left-to-right and right-to-left text scrolling diff --git a/examples/ScanPixels/ScanPixels.ino b/examples/ScanPixels/ScanPixels.ino index 4fe9a92..39a81ad 100644 --- a/examples/ScanPixels/ScanPixels.ino +++ b/examples/ScanPixels/ScanPixels.ino @@ -2,7 +2,6 @@ #define DELAY 10 //Sets the delay between each frame in mS #define NUMBER_OF_DISPLAYS 4 //Sets the number of display (4 for this example) -uint8_t matrix_b[NUMBER_OF_DISPLAYS*8]; //Column-adressed array to store what's on the display /* Initialize the library. The 4 means that the CS pin is connected to pin D4. @@ -31,32 +30,28 @@ void loop(){ //This sets an LED ON sequentially per row. for(int i=0;i<8;i++){ //Repreat per row for(int k=0;k<(NUMBER_OF_DISPLAYS*8);k++){ //Repeat per column - matrix_b[k] |= (1< sentence=A library for the MAX7219 LED display drivers. diff --git a/src/simple_matrix.cpp b/src/simple_matrix.cpp index 24ca0cc..3d3deaf 100644 --- a/src/simple_matrix.cpp +++ b/src/simple_matrix.cpp @@ -12,7 +12,7 @@ Originally designed for the University of New Haven's Author: Jamal Bouajjaj ********************************************************************************/ // Macro to treat the 1D array _matrix as a 2D array -#define _GET_MATRIX_LOC(_Y, _X) _matrix[(8*_Y)+_X] +#define _GET_MATRIX_LOC(_MATRIX_NUMB, _ROW_NUMB) _matrix[(8*_MATRIX_NUMB)+_ROW_NUMB] /******************************************************************************** Constructor @@ -27,6 +27,8 @@ simpleMatrix::simpleMatrix(int pin, bool rotateIndividualDislay, unsigned int nu _matrix = new uint8_t[(_NUMB_OF_LED_MATRICES+1)*8]; // A copy of a column_addressed matrix. Used as memory for when new stuff is scrolled unto the display. _matrix_col = new uint8_t[(_NUMB_OF_LED_MATRICES)*8]; + memset(_matrix, 0, (_NUMB_OF_LED_MATRICES+1)*8); + memset(_matrix_col, 0, (_NUMB_OF_LED_MATRICES)*8); pinMode(_DL_PIN,OUTPUT); digitalWrite(_DL_PIN,HIGH); } @@ -36,11 +38,11 @@ Low Level Function //Sends a command to a single MS7219 void simpleMatrix::sendCommandtoOne(uint8_t command, uint8_t data, uint8_t display){ uint8_t d[_NUMB_OF_LED_MATRICES*2]; //Array that containts data to be sent + memset(d, 0, _NUMB_OF_LED_MATRICES*2); d[2*display] = command; d[(2*display)+1] = data; digitalWrite(_DL_PIN,LOW); for(int k=0;k<_NUMB_OF_LED_MATRICES*2;k++){SPI.transfer(d[k]);} // Send data - for(int k=0;k<_NUMB_OF_LED_MATRICES*8;k++){_matrix_col[k] = 0; _GET_MATRIX_LOC(k/_NUMB_OF_LED_MATRICES, k%_NUMB_OF_LED_MATRICES) = 0;} digitalWrite(_DL_PIN,HIGH); } @@ -63,7 +65,7 @@ void simpleMatrix::senddisplay(){ SPI.transfer(r+1); SPI.transfer(_GET_MATRIX_LOC(i, r)); } - digitalWrite(_DL_PIN,HIGH); + digitalWrite(_DL_PIN,HIGH); } } @@ -85,10 +87,11 @@ High-Level functions //Converts a column-addressed buffer to a display-row-addressed buffer and sends it void simpleMatrix::sendMatrixBuffer(uint8_t *mat, int start_from){ - for(int i=0;i<_NUMB_OF_LED_MATRICES;i++){ - for(int k=0;k<8;k++){ - _matrix_col[k+(i*8)] = mat[k+(i*8)+start_from]; - _GET_MATRIX_LOC(i, k) = mat[k+(i*8)+start_from]; //Copy *mat to *_matrix with it split up + if(mat != NULL){ + for(int i=0;i<_NUMB_OF_LED_MATRICES;i++){ + for(int k=0;k<8;k++){ + _matrix_col[k+(i*8)] = mat[k+(i*8)+start_from]; + } } } //Function to transpose display (Thanks Spencer Hopwood!) @@ -101,9 +104,9 @@ void simpleMatrix::sendMatrixBuffer(uint8_t *mat, int start_from){ // To combat this, there is a flag which will decide whether or not to rotate // each matrix's buffer by 180degrees if(_ROTATE_INDIV_DISPLAY){ - temp[7-i] |= ((_GET_MATRIX_LOC(d, k) & bitmask_v) >> (i)) << (7-k); + temp[7-i] |= ((_matrix_col[k+(d*8)] & bitmask_v) >> (i)) << (7-k); }else{ - temp[i] |= ((_GET_MATRIX_LOC(d, k) & bitmask_v) >> (i)) << (k); + temp[i] |= ((_matrix_col[k+(d*8)] & bitmask_v) >> (i)) << (k); } } } @@ -114,8 +117,11 @@ void simpleMatrix::sendMatrixBuffer(uint8_t *mat, int start_from){ //Fills the display. Can fill all or some displays void simpleMatrix::fillDisplay(int from, int to){ - if(to==(int)0x8000){to=_NUMB_OF_LED_MATRICES-1;} - for(int i=from;i<(to+1);i++){ + if(to==(int)0x8000){to=_NUMB_OF_LED_MATRICES;} // If to is default, set to end of matrix + memset(_matrix_col+(from*8), 0xFF, (to-from)*8); // Set the internal column-addressed column to said value + // Due to the easiness of this operation, manually update the row/display addressed array and send it + // instead of using the sendMatrixBuffer function + for(int i=from;i