32x32 led ghetto matrix :)

I mashed it all into 1 file and added some comments

// 2k10 OSGELD

// i am scanning by row (instead of normal pixel by pixel), which overloads the 595's
// there are 2 595 per row / col piggy backed on eachother in a kludge to bring 
// it more in spec, your results may vary

// this array of bytes is used to keep track of where
// we are, X is the first 4 bytes these are columns
// combination of those 32 bits repersent what pixels 
// are lit for every row.

// Y is the last 4 bytes in the array, 
// each of the 32 bits is toggled on one at a time in order

// !be careful on your wiring!

// its still backwards on mine so i start with lsb and shift left
// instead of to the right which would have made more since
byte screenBuffer[8] = 
{
  B00000000, B00000000,
  B00000000, B00000000, 
  B00000000, B00000000, 
  B00000000, B00000000};
  
void setup() 
{
  // setup pins for screen (595's)
  // enable the atmega 328s hardware spi port
  screenInit(); // delay 10
}

void loop() 
{
  // update the screen as fast as it can
  bitmapUpdate();
}
///////////////////////////////////
// enable the atmega 328s hardware spi port
// this can be found on the fourm
void screenInit()
{
  DDRB = DDRB | B00001101; 
  // screen must be on pins
  // 10 latch
  // 11 data
  // 13 clock
  
  // setup hardware spi
  byte clr;
  SPCR |= ( (1<<SPE) | (1<<MSTR) ); // enable SPI as master
  SPCR &= ~( (1<<SPR1) | (1<<SPR0) ); // clear prescaler bits
  clr = SPSR; // clear SPI status reg
  clr = SPDR; // clear SPI data reg
  SPSR |= (1<<SPI2X); // set prescaler bits
  delay(10);
}

// what you use to send data to the screen
void screenFlip()
{
  screenOn(false); // turn off latch
    //x
    screenOut(screenBuffer[3]);
    screenOut(screenBuffer[2]); 
    screenOut(screenBuffer[1]); 
    screenOut(screenBuffer[0]);
    //y    
    screenOut(screenBuffer[7]); 
    screenOut(screenBuffer[6]); 
    screenOut(screenBuffer[5]); 
    screenOut(screenBuffer[4]);
  screenOn(true); // tun on latch, showing screen
}

void screenOn(boolean ON) // toggle the latch
{
  if(ON) bitSet(PORTB, 2); // HIGH
  else bitClear(PORTB, 2); // LOW
}

// hardware send data to screen
// stripped down version of what you would
// find on the hardware spi fourm topics
void screenOut(byte data)
{
  SPDR = data;                    
  while (!(SPSR & (1<<SPIF))){}   
}
///////////////////////////////////
// bitmap data, original file pbm image format saved in ascii
// as text 1's and 0's from the gimp, arduino formatted with 
// a little hand magic in notepad ++
byte mac[32][4]  =
{
  {B00000000, B00000000, B00000000, B00000000},
  {B00111111, B11111111, B11111111, B10000000},
  {B01100000, B00000000, B00000000, B11000000},
  {B01000000, B00000000, B00000000, B01000000},
  {B01000111, B11111111, B11111100, B01000000},
  {B01001000, B00000000, B00000010, B01000000},
  {B01001000, B00000000, B00000010, B01000100}, 
  {B01001000, B00000000, B00000010, B01000010}, 
  {B01001000, B01000100, B01000010, B01001000},
  {B01001000, B01000100, B01000010, B01001010},
  {B01001000, B00000100, B00000010, B01010010},
  {B01001000, B00000100, B00000010, B01001001},
  {B01001000, B00001100, B00000010, B01010110},
  {B01001000, B00000000, B00000010, B01001010},
  {B01001000, B00100001, B00000010, B01010101},
  {B01001000, B00011110, B00000010, B01011011},
  {B01001000, B00000000, B00000010, B01001101},
  {B01001000, B00000000, B00000010, B01010110},
  {B01000111, B11111111, B11111100, B01011011},
  {B01000000, B00000000, B00000000, B01011101},
  {B01000000, B00000000, B00000000, B01010111},
  {B01000000, B00000000, B00000000, B01011011},
  {B01000000, B00000000, B00000000, B01011101},
  {B01000110, B00000000, B01111110, B01011111},
  {B01000000, B00000000, B00000000, B01010111},
  {B01000000, B00000000, B00000000, B01011101},
  {B01000000, B00000000, B00000000, B01011111},
  {B01111111, B11111111, B11111111, B11011111},
  {B00100000, B00000000, B00000000, B10011011},
  {B00100000, B00000000, B00000000, B10011111},
  {B00111111, B11111111, B11111111, B10011111},
  {B00000000, B00000000, B00000000, B00011111}};

void bitmapUpdate()
{
  int x; // col counter
  int y; // row counter
  for(y = 0; y < 32; y++) // for 32 rows do...
  { // 32 rows + each row is comprised of 4 bytes of X on off data so...
    for(x = 0; x < 4; x++) 
    {
      screenBuffer[x] = mac[y][x];
      // read the current row X data into into the screen buffers 0-3
    }

    // after the X data for the row is in the buffer
    // we need to format the row position data for the 595's,
    // only 1 line at a time means we have to shuffle a
    // single bit though 32 bits(over the last 4 bytes of the buffer array)
    switch(y / 8)
    {
      case 0: // ie 3 / 8 = integer 0
        if(screenBuffer[4] == 0) // see if the first 8 rows is turned off
        { // if so
          screenBuffer[7] = B00000000; // turn off the last 8 rows
          screenBuffer[4] = B00000001; // set the first bit to one, mines backwards
        }
        else // if not
        {
          screenBuffer[4] = screenBuffer[4] << 1; // shift the bit one space, or to the next row
        }
      break;
      // repeat 7 more times 
      case 1:
        if(screenBuffer[5] == 0)
        {
          screenBuffer[4] = B00000000;
          screenBuffer[5] = B00000001;
        }
        else
        {
          screenBuffer[5] = screenBuffer[5] << 1; 
        }
      break;
      
      case 2:
        if(screenBuffer[6] == 0)
        {
          screenBuffer[5] = B00000000;
          screenBuffer[6] = B00000001;
        }
        else
        {
          screenBuffer[6] = screenBuffer[6] << 1; 
        }
      break;
      
      case 3:
        if(screenBuffer[7] == 0)
        {
          screenBuffer[6] = B00000000;
          screenBuffer[7] = B00000001;
        }
        else
        {
          screenBuffer[7] = screenBuffer[7] << 1; 
        }
      break;
    } // end switch  
    screenFlip(); // show screen
  } // end y for loop   
} // end function

// wait for next call