Im testing if i can use my 16x32 RGB ledMatrix from adafruit with an interrupt routine.
In void loop() I'm setting a pixel on position 0,0 to red and in my interrupt routine I am blinking a led every second. I'm using Timer1 (16bit) bc my compare match register for 1Hz is higher then 256.
My promblem is that the interrupt routine and the loop routine work individually but when i put them together then only the red pixel is been set.
Does somebody know why they can't go together?
grtz
Code: Select all
#include <avr/io.h>
#include <avr/interrupt.h>
#include <Adafruit_GFX.h> // Core graphics library
#include <RGBmatrixPanel.h> // Hardware-specific library
int led =13;
#define CLK 8 // MUST be on PORTB! (Use pin 11 on Mega)
#define LAT A3
#define OE 9
#define A A0
#define B A1
#define C A2
RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false);
void setup()
{
cli();//stop interrupts
//set timer1 interrupt at 1Hz
TCCR1A = 0;// set entire TCCR1A register to 0
TCCR1B = 0;// same for TCCR1B
TCNT1 = 0;//initialize counter value to 0
// set compare match register for 1hz increments
OCR1A = 15624;// = (16*10^6) / (1*1024) - 1 (must be <65536)
// turn on CTC mode
TCCR1B |= (1 << WGM12);
// Set CS12 and CS10 bits for 1024 prescaler
TCCR1B |= (1 << CS12) | (1 << CS10);
// enable timer compare interrupt
TIMSK1 |= (1 << OCIE1A);
sei();//allow interrupts
pinMode(led,OUTPUT);
matrix.begin();
}
ISR(TIMER1_COMPA_vect)//interrupt routine
{
digitalWrite(led,!digitalRead(led));
}
void loop()
{
matrix.drawPixel(0, 0, matrix.Color333(7, 0, 0));
}