Hello folks. I'm working with someone on making a 42x11 LED matrix. I put the matrix together and he put the boards and code together. We're using TLC5926 chips to control the low end and A2982 chips to control the high side. I'm testing with 1 high side board (8 rows) and 1 low side board (16 columns) before hooking everything up. The sketch that we have should just scroll HELLO. He set up a couple shiftregister libraries, one for 8 and one for 16 bit.
The problem comes in that, when the sketch is run, there is no scrolling. All of the lights just come on. I've attached the libraries and the sketch is below. Could someone please point out where we may have gone wrong? Any help is appreciated.
/*
* Show messages on an 8x8 led matrix,
* scrolling from right to left.
*
* Uses FrequencyTimer2 library to
* constantly run an interrupt routine
* at a specified frequency. This
* refreshes the display without the
* main loop having to do anything.
*
*/
#include <FrequencyTimer2.h>
#include <ShiftRegister8.h>
#include <ShiftRegister16.h>
#define NUM_ROWS 8
#define NUM_COLUMNS 16
#define NUM_LOW_SIDE_BOARDS 1
#define NUM_HIGH_SIDE_BOARDS 1
#define NUM_PATTERN_ROWS 8
#define NUM_PATTERN_COLUMNS 8
ShiftRegister8 high_side(3, 4, 5); //data, clock, latch
ShiftRegister16 low_side(6, 7, 8); //data, clock, latch
const uint8_t low_side_enable_pin = 9; // enable to low side drivers
void set_column(uint8_t ii);
void clear_column(uint8_t ii);
void set_row(uint8_t ii);
void clear_row(uint8_t ii);
#define SPACE { \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0} \
}
#define H { \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 1, 1, 1, 1, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0} \
}
#define E { \
{0, 1, 1, 1, 1, 1, 1, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 1, 1, 1, 1, 1, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 1, 1, 1, 1, 1, 0} \
}
#define L { \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 1, 1, 1, 1, 1, 0} \
}
#define O { \
{0, 0, 0, 1, 1, 0, 0, 0}, \
{0, 0, 1, 0, 0, 1, 0, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 0, 1, 0, 0, 1, 0, 0}, \
{0, 0, 0, 1, 1, 0, 0, 0} \
}
byte col = 0;
byte leds[NUM_COLUMNS][NUM_ROWS];
uint16_t columns[NUM_LOW_SIDE_BOARDS] = {0};
uint8_t rows[NUM_HIGH_SIDE_BOARDS] = {0};
const int numPatterns = 6;
byte patterns[numPatterns][NUM_PATTERN_COLUMNS][NUM_PATTERN_ROWS] = {
H,E,L,L,O,SPACE
};
int pattern = 0;
void setup() {
clearLeds();
// Turn off toggling of pin 11
FrequencyTimer2::disable();
// Set refresh rate (interrupt timeout period)
FrequencyTimer2::setPeriod(2000);
// Set interrupt routine to be called
FrequencyTimer2::setOnOverflow(display);
setPattern(pattern);
pinMode(low_side_enable_pin, OUTPUT);
digitalWrite(low_side_enable_pin, LOW); // enable the display
}
void loop() {
pattern = ++pattern % numPatterns;
slidePattern(pattern, 60);
}
void clearLeds() {
// Clear display array
for (int i = 0; i < NUM_COLUMNS; i++) {
for (int j = 0; j < NUM_ROWS; j++) {
leds[i][j] = 0;
}
}
}
void setPattern(int pattern) {
for (int i = 0; i < NUM_PATTERN_COLUMNS; i++) {
for (int j = 0; j < NUM_PATTERN_ROWS; j++) {
leds[i][j] = patterns[pattern][i][j];
}
}
}
void slidePattern(int pattern, int del) {
for (int l = 0; l < NUM_ROWS; l++) {
for (int i = 0; i < NUM_ROWS - 1; i++) {
for (int j = 0; j < NUM_COLUMNS; j++) {
leds[j][i] = leds[j][i+1];
}
}
for (int j = 0; j < NUM_PATTERN_COLUMNS; j++) {
leds[j][NUM_ROWS - 1] = patterns[pattern][j][0 + l];
}
delay(del);
}
}
// Interrupt routine
void display() {
clear_column(col); // Turn whole previous column off
col++;
if (col == NUM_COLUMNS) {
col = 0;
}
for (int row = 0; row < NUM_ROWS; row++) {
if (leds[col][NUM_ROWS - 1 - row] == 1) {
set_row(row); // Turn on this led
}
else {
clear_row(row); // Turn off this led
}
}
high_side.loadValues(rows, NUM_HIGH_SIDE_BOARDS);
set_column(col); // Turn whole column on at once (for equal lighting times)
}
void set_column(uint8_t ii){
uint8_t entry_index = ii / 16;
uint8_t bit_index = ii % 16;
columns[entry_index] |= ((uint16_t) 1) << bit_index;
low_side.loadValues(columns, NUM_LOW_SIDE_BOARDS);
}
void clear_column(uint8_t ii){
uint8_t entry_index = ii / 16;
uint8_t bit_index = ii % 16;
columns[entry_index] &= ~(((uint16_t) 1) << bit_index);
low_side.loadValues(columns, NUM_LOW_SIDE_BOARDS);
}
void set_row(uint8_t ii){
uint8_t entry_index = ii / 8;
uint8_t bit_index = ii % 8;
rows[entry_index] |= 1 << bit_index;
}
void clear_row(uint8_t ii){
uint8_t entry_index = ii / 8;
uint8_t bit_index = ii % 8;
rows[entry_index] &= ~(1 << bit_index);
}
ShiftRegister-1[1].zip (4.42 KB)