Go Down

Topic: Timer1 refresh problem with 8x8 LED Matrix (Read 690 times) previous topic - next topic

darknails

I'm using two 74HC595 to control a 8x8 LED Matrix with the row-column scanning method. I want to switch between two patterns with specified times, using the TimerOne.h library similar to that shown here.
http://arduino.cc/playground/Main/DirectDriveLEDMatrix#Timer1

But somehow my code does work. Can someone point out what I did wrong?
Here is my code

Code: [Select]

#include <Streaming.h>
#include <TimerOne.h>

// ST_CP of 74HC595
int latchPin = 6;
// SH_CP of 74HC595
int clockPin = 5;
// DS of 74HC595
int dataPin = 7;

int ledPin = 9;

PROGMEM prog_uint8_t BitMap1[8] = {   // store in program memory to save RAM
        B00011000,
        B00111100,
        B00011000,
        B00000000,
        B00011000,
        B00011000,
        B00011000,
        B00111100
};


  PROGMEM prog_uint8_t BitMap3[8] = {   // store in program memory to save RAM
        B00000000,
        B11100111,
        B11100111,
        B01111110,
        B01111110,
        B00111100,
        B00111100,
        B00011000
};

byte Map[8];

#define row_no 8
#define col_no 8


void setup()
{
  pinMode(ledPin, OUTPUT);
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
 
  Serial.begin(9600);

  Timer1.initialize(100);
  Timer1.attachInterrupt(DisplayBitMap);
}




void loop()
{
  // Clear screen
  for(int i=0; i<8; i++){
   Map[i] = 0;
  }
  delay(1000);

  // load first pattern
  for(int i=0; i<8; i++){
   Map[i] = pgm_read_byte (&BitMap1[i]);
  }
  delay(1000);

  // Clear screen
  for(int i=0; i<8; i++){
   Map[i] = 0;
  }
  delay(1000);
 
  // load second pattern
  for(int i=0; i<8; i++){
   Map[i] = pgm_read_byte (&BitMap3[i]);
  }
  delay(1000);


}

// Row-Column Scanning
void DisplayBitMap()
{
   // Initialize in the off configuration
   int colData;
   int rowData;


   for (byte x=0; x<row_no; ++x) {

   byte data = Map[x];   // fetch data from program memory

   for (byte y=0; y<col_no; ++y) {
     colData=0;
     rowData=255;
   
     if (data & (1<<(col_no-y-1))) {
       // turn on the LED at location (x,y)
       colData = 1 << y;
       rowData &= ~(1 << x);
       } else {
       // turn off the LED at location (x,y)
       colData = 0;
       rowData = 255;
       }
       digitalWrite(latchPin, LOW);
       shiftOut(dataPin, clockPin, LSBFIRST, colData);
       shiftOut(dataPin, clockPin, LSBFIRST, rowData);
       digitalWrite(latchPin, HIGH);

     }
   }
}

Go Up