here are the other 2 sketches i need to combine with the previous 2
#define CHIPSELECT 10//Chip Select Line
#define SPICLOCK 13//Master Clock
#define DATAOUT 11//DataOut to DataIn on Backpack
#define DATAIN 12//DataIn from DataOut on Backpack
//simple array for data frames - you can use 0-3 for the color settings on the RG display or 0-7 for the RGB Matrixs//
int databuffer[8][8][8] ={
{
{0,0,0,0,0,0,0,0},
{0,0,32,32,32,32,32,0},
{0,32,0,0,0,232,32,0},
{0,32,0,0,0,232,32,0},
{0,32,0,0,0,232,32,0},
{0,32,0,0,0,232,32,0},
{0,0,32,32,32,32,32,0},
{0,0,0,0,0,0,0,3}
},
{
{0,0,0,0,0,0,0,0},
{0,0,0,32,32,0,0,0},
{0,0,32,32,32,32,0,0},
{0,32,0,0,0,232,32,0},
{0,32,32,32,228,232,32,0},
{0,32,0,0,0,232,32,0},
{0,32,0,0,0,232,32,0},
{0,0,0,0,0,0,3,0}
},
{
{0,0,0,0,0,0,0,0},
{0,32,32,32,32,32,32,0},
{0,0,0,0,0,232,32,0},
{0,0,0,0,0,232,32,0},
{0,0,32,32,228,232,32,0},
{0,0,0,0,0,232,32,0},
{0,0,0,0,0,232,32,0},
{0,0,0,0,0,3,0,0}
},
{
{0,0,0,0,0,0,0,0},
{0,32,32,32,32,32,32,0},
{0,0,0,232,32,0,0,0},
{0,0,0,232,32,0,0,0},
{0,0,0,232,32,0,0,0},
{0,0,0,232,32,0,0,0},
{0,0,0,232,32,0,0,0},
{0,0,0,0,3,0,0,0}
},
{
{0,0,0,0,0,0,0,0},
{0,0,32,32,32,32,32,0},
{0,32,0,0,0,232,32,0},
{0,32,0,0,0,232,32,0},
{0,0,32,32,228,232,32,0},
{0,0,0,0,0,232,32,0},
{0,0,0,0,0,232,32,0},
{0,0,0,3,0,0,0,0}
},
{
{0,0,0,0,0,0,0,0},
{0,32,0,0,0,232,32,0},
{0,32,0,0,0,232,32,0},
{0,32,0,0,0,232,32,0},
{0,32,0,0,0,232,32,0},
{0,32,32,32,228,232,32,0},
{0,0,32,32,32,32,0,0},
{0,0,3,0,0,0,0,0}
},
{
{0,0,0,0,0,0,0,0},
{0,32,0,0,0,32,32,0},
{0,32,0,0,0,232,32,0},
{0,32,0,0,32,228,32,0},
{0,32,0,32,0,232,32,0},
{0,32,32,0,0,232,32,0},
{0,32,0,0,0,232,32,0},
{0,3,0,0,0,0,0,0}
},
{
{0,0,0,0,0,0,0,0},
{0,32,0,0,0,228,32,0},
{0,0,32,0,0,232,32,0},
{0,0,0,32,0,232,32,0},
{0,0,0,32,228,232,32,0},
{0,0,32,0,0,232,32,0},
{0,32,0,0,0,232,32,0},
{3,0,0,0,0,0,0,0}
}
} ;
int z=0;
// SPI data load / transfer function - thanks Heather Dewey-Hagborg //
char spi_transfer(volatile char data)
{
SPDR = data; // Start the transmission
while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission
{
};
}
void clearDisplay() {
for (int i=0;i<8;i++) for (int j=0;j<8;j++)
{ spi_transfer( 0 ); }
delay(50);
}
void setup()
{
byte clr;
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
clr=SPSR;
clr=SPDR;
delay(10);
clearDisplay();
}
void loop()
{
int z=0;
//loop though frames #8 //
for (int z=0;z<8;z++) {
delay(600);
digitalWrite(CHIPSELECT,LOW); // enable the ChipSelec
delayMicroseconds(500);
for (int i=0;i<8;i++) {
for (int j=0;j<8;j++) {
spi_transfer( databuffer[z][i][j] );
}
}
digitalWrite(CHIPSELECT,HIGH); // disable the ChipSelect
delayMicroseconds(500);
}
delay(100);
}
// Simple program to test using the Arduino with the RGB Matrix
// & Backpack from Sparkfun. Code is a combination of Heather Dewey-Hagborg,
// Arduino Forum user: Little-Scale, and // Daniel Hirschmann. Enjoy!
//
// The Backpack requires 125Khz SPI, which is the slowest rate
// at which the Arduino's hardware SPI bus can communicate at.
//
// We need to send SPI to the backpack in the following steps:
// 1) Activate ChipSelect;
// 2) Wait 500microseconds;
// 3) Transfer 64bytes @ 125KHz (1 byte for each RGB LED in the matrix);
// 4) De-activate ChipSelect;
// 5) Wait 500microseconds
// Repeat however often you like!
#define CHIPSELECT 10//ss
#define SPICLOCK 13//sck
#define DATAOUT 11//MOSI
#define DATAIN 12//MISO
#define RED 0xE0 // For code readability.
#define GREEN 0x1C // Only 8 colors available
#define BLUE 0x07 // but variation possible with
#define ORANGE 0xFC // brightness (see Sparkfun doc).
#define MAGENTA 0xE3
#define TEAL 0x1F
#define WHITE 0xFF
#define BLACK 0x00
byte color_tst_tbl[] = {32,64,96,1,7,228,52,40}; // Table of color codes, one color duplicated to get 8 entries for test purpose.
byte pattern[] = { // Test pattern to be displayed on the matrix, entries in binary for learning purpose.
B11111111, // So you can see which led is on (1) or off (0=BLACK) on your pattern.
B00000000, // Just change it to test your own patterns.
B11111111, // We can also use hex notation: B11111111 is 0xFF in hexa
B00000000,
B11111111,
B00000000,
B11111111,
B00000000
};
char spi_transfer(volatile char data)
{
SPDR = data; // Start the transmission
while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission
{
};
}
void setup()
{
byte clr;
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)
*/
clr=SPSR;
clr=SPDR;
delay(10);
}
void loop()
{
delay(150);
int idx = 0;
digitalWrite(CHIPSELECT,LOW); // enable the ChipSelect on the backpack
delayMicroseconds(500);
for (int i=0;i<8;i++)
{
for (int j=0;j<8;j++)
{
if (bitRead(pattern[i],j) == 0) //bitRead funcion is used to get each 8 bit of the 8 bytes pattern table (64 bits in total).
{ spi_transfer(BLACK);} // bit is 0 -> Transfer Black color.
else
{ spi_transfer(color_tst_tbl[j]);} // bit is 1 -> Transfer a color choosen in the color test table.
idx++;
}
} // 64 bytes should have been transfered to the RGB matrix.
digitalWrite(CHIPSELECT,HIGH); // disable the ChipSelect on the backpack
// What you've send is displayed on the matrix.
delayMicroseconds(500);
delay(150);
idx = 0;
digitalWrite(CHIPSELECT,LOW); // enable the ChipSelect on the backpack
delayMicroseconds(500);
for (int i=0;i<8;i++)
{
for (int j=0;j<8;j++)
{
if (bitRead(pattern[i],j) != 0) //bitRead funcion is used to get each 8 bit of the 8 bytes pattern table (64 bits in total).
{ spi_transfer(BLACK);} // bit is 0 -> Transfer Black color.
else
{ spi_transfer(color_tst_tbl[j]);} // bit is 1 -> Transfer a color choosen in the color test table.
idx++;
}
} // 64 bytes should have been transfered to the RGB matrix.
digitalWrite(CHIPSELECT,HIGH); // disable the ChipSelect on the backpack
// What you've send is displayed on the matrix.
delayMicroseconds(500);
}