ARR! you are right, I was thinking maybe that was NOT in the ISR but the setup area, but you put it there just for that purpose! Good job, lol.
Hey on bitshifting, I would eventually have to reset the variable from 00000000 to 10000000 once the 1 has been shifted off the byte. This would mean having an if-then statement of some sort to check and fix the byte. Would I be faster to use the port manipulation without any logic checking?
here's what I noticed using bitshifting:
/* Beginings of LED matrix controlled by arduino mega 2560*/
#include <avr/IO.h>
#include <avr/pgmspace.h>
#include <avr/Interrupt.h>
#include <SPI.h>
/*******************************************************************************
************************** Global Variables ************************************
*******************************************************************************/
volatile byte Row; // Volatiles - Variables that can jump into ISRs!
/*********************************************************************************
************************ Port Settings *******************************************
*********************************************************************************/
//ROW SCANNER INTERRUPT SERVICE ROUTINE
ISR(TIMER1_OVF_vect) {
TCNT1=0xFD62; // set initial value to remove time error (16bit counter register) FBEF=60?
Row = Row << 1; //shifts the row that is one over 1 bit, 00000001 to 00000010 and so on
if (Row==0) {
Row = B00000001; //Checks for Row = 00000000 then starts at row 00000001 again
}
PORTD = Row; //Puts all port D to output based on Row Byte
}
void setup()
{
DDRD = B11111111; // sets Arduino pins 0-7 as outputs
Row = B00000001; //Preparing volatiles
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
TIMSK1=0x01; // enabled global and timer overflow interrupt;
TCCR1A = 0x00; // normal operation page 148 (mode0);
TCNT1=0xFD62; // set initial value to remove time error (16bit counter register)
TCCR1B = 0x04; // start timer/ set clock
}
void loop()
{
digitalWrite(11, LOW); //SET OUTPUT ENABLE ON
digitalWrite(10, HIGH); // set Strobe/Latch LOW
digitalWrite(8, HIGH); // set clock LOW
digitalWrite(9, HIGH); // set the data output high
digitalWrite(8, LOW); // set clock LOW
digitalWrite(8, HIGH); // set the clock HIGH
delay(200); // wait for a second
digitalWrite(8, LOW); // set clock LOW
digitalWrite(8, HIGH); // set the clock HIGH
delay(200); // wait for a second
digitalWrite(9, LOW); // set the data output
digitalWrite(8, LOW); // set clock LOW
digitalWrite(8, HIGH); // set the clock HIGH
delay(200); // wait for a second
digitalWrite(8, LOW); // set clock LOW
digitalWrite(8, HIGH); // set the clock HIGH
delay(200); // wait for a second
}
AWSOME! I got it working, One problem solved of many to come! lol, now I need to get this thing refreshing faster, currently it is flickering horribly, mainly because it was set to do 60hz and 50% duty cycle on a single row, but I just added 7 rows to the 60hz refresh ISR, leaving each individual row at like 10hz refresh rate and 12.5% duty cycle....
I'll be back...
If you have any other optimization suggestions I would gladly accept your advice and compare.