All pastes #2087514 Raw Edit

Unnamed

public text v1 · immutable
#2087514 ·published 2011-10-07 05:15 UTC
rendered paste body
// Writing to the RGB Serial Backpack Matrix from SparkFun Electronics
// by Ryan Owens
// Copyright SparkFun Electronics

//Define the "Normal" Colors
#define BLACK  0
#define RED  0xE0
#define GREEN  0x1C
#define BLUE  0x03
#define ORANGE  RED|GREEN
#define MAGENTA  RED|BLUE
#define TEAL  BLUE|GREEN
#define WHITE (RED|GREEN|BLUE)-0xA0

//Define the SPI Pin Numbers
#define DATAOUT 11//MOSI
#define DATAIN  12//MISO 
#define SPICLOCK  13//sck
#define SLAVESELECT 10//ss

//Define the variables we'll need later in the program
char color_buffer [64]; 

int y = 0;   

int x = 0; 

void setup() 
{  
  //SPI Bus setup
  SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1);	//Enable SPI HW, Master Mode, divide clock by 16    //SPI Bus setup
  
  //Set the pin modes for the RGB matrix
  pinMode(DATAOUT, OUTPUT);
  pinMode(DATAIN, INPUT);
  pinMode(SPICLOCK,OUTPUT);
  pinMode(SLAVESELECT,OUTPUT);
  
  //Make sure the RGB matrix is deactivated
 // digitalWrite(SLAVESELECT,HIGH); 

} 
 
void loop() 
{
  
  delay(1000);
  
while (y < 64) {
   
   color_buffer[x]=ORANGE;
   
   delay(10);
   x++;
   
    //Activate the RGB Matrix
  digitalWrite(SLAVESELECT, LOW);
  //Send the color buffer to the RGB Matrix
  for(int LED=0; LED<64; LED++){
    spi_transfer(color_buffer[LED]);
  }
 
}


 
 ++y;

 delay(1000);

 x=64;
y=0;
  
while (y < 60) {
   
   color_buffer[x]=BLUE;
   
   delay(10);
   --x;
   
    //Activate the RGB Matrix
  digitalWrite(SLAVESELECT, LOW);
  //Send the color buffer to the RGB Matrix
  for(int LED=0; LED<64; LED++){
    spi_transfer(color_buffer[LED]);
  }
  
} 


 ++y;
 x=0;
 y=0;
 while (y < 60) {
   
   color_buffer[x]=RED;
   
   delay(10);
   x++;
   
    //Activate the RGB Matrix
  digitalWrite(SLAVESELECT, LOW);
  //Send the color buffer to the RGB Matrix
  for(int LED=0; LED<64; LED++){
    spi_transfer(color_buffer[LED]);
  }
 
}


 
 ++y;

 //delay(150);
 
 delay(1000);
//digitalWrite(SLAVESELECT, HIGH); 
//while(1);
//delay(150);
 //Deactivate the RGB matrix.
  //digitalWrite(SLAVESELECT, HIGH);
  //while(1);
  //delay(150); // allow some time for the Serial data to be sent 

} 



//Use this command to send a single color value to the RGB matrix.
//NOTE: You must send 64 color values to the RGB matrix before it displays an image!
char spi_transfer(volatile char data)
{
  SPDR = data;                    // Start the transmission
  while (!(SPSR & (1<<SPIF)))     // Wait for the end of the transmission
  {
  };
  return SPDR;                    // return the received byte
}