I’m having challenges daisy chaining 2 Red/Green LED Matrices (http://www.sparkfun.com/products/759) together.
I have the following basic code working, and what I’d like to do is extend this to fill two matrices.
It’s my understanding that I need to configure them and specify the number of boards by doing something like the following in setup and extending the loop to count to 128 instead of 64, but of course that’s not working.
If anyone can help me get two matrices working together it would be greatly appreciated. I already have text scrolling across one matrix and am looking forward to doing it across more.
// Configure boards
digitalWrite(CHIPSELECT,LOW); // enable the ChipSelect on the backpack
delayMicroseconds(500);
spi_transfer('%'); // % byte
spi_transfer('2'); // num boards
digitalWrite(CHIPSELECT,HIGH); // disable the ChipSelect on the backpack
delayMicroseconds(10);
#define CHIPSELECT 10
#define SPICLOCK 13
#define DATAOUT 11
#define DATAIN 12
char spi_transfer(volatile char data) {
SPDR = data;
while (!(SPSR & (1<<SPIF))) {
};
}
void setup(){
pinMode(DATAOUT,OUTPUT);
pinMode(SPICLOCK,OUTPUT);
pinMode(CHIPSELECT,OUTPUT);
digitalWrite(CHIPSELECT,HIGH); //disable device
SPCR = B01010001; //SPI Registers
SPSR = SPSR & B11111110; //make sure the speed is 125KHz
/*
SPCR bits:
7: SPIEE - enables SPI interrupt when high
6: SPE - enable SPI bus when high
5: DORD - LSB first when high, MSB first when low
4: MSTR - arduino is in master mode when high, slave when low
3: CPOL - data clock idle when high if 1, idle when low if 0
2: CPHA - data on falling edge of clock when high, rising edge when low
1: SPR1 - set speed of SPI bus
0: SPR0 - set speed of SPI bus (00 is fastest @ 4MHz, 11 is slowest @ 250KHz)
*/
delay(10);
}
void loop(){
// Compose frame data
// Draw current frame
delay(80);
digitalWrite(CHIPSELECT,LOW); // enable the ChipSelect on the backpack
delayMicroseconds(500);
for (int i=0;i<64;i++) {
// draw a red, green or orange LED
spi_transfer( (i % 3) + 1);
}
digitalWrite(CHIPSELECT,HIGH); // disable the ChipSelect on the backpack
delayMicroseconds(500);
}
Thank you!