Just started with the Arduino, finding 'scoping' a bit of an issue, usually code via assembler or Basic. So my problem is that I'm trying to write/convert a library for product I already have using a PIC, and I can't for the life of me sort out scoping errors. I have an ISR I want to place in the library but it produces a scoping error for the variables it uses. I also get scoping errors when I try to initialize variables in the .cpp, especially arrays either empty or filled with values.
Any help or guidance would be gratefully received, copy of files below:
Copy of sketch:
//EGamer tester for Library
//Includes
#include <avr/pgmspace.h>
#include <Egamer.h>
Egamer Eg;
//Setup Vars
volatile int Trac = 0;
//Screen variables
byte Display[8];
byte MatCol[] = {40,0,8,24,16,32,48,56};
byte Backg[24];
byte TxtLayer[8];
byte Xpos = 0;
byte Ypos = 0;
//Setup constants
const byte Splash[] PROGMEM = {31,21,21,0,255,129,133,199};
//Main setup function
void setup()
{
Eg.Config();
//eGamer Splash Screen
for (int i = 0; i < 8; i++){
Display[i] = pgm_read_byte(&Splash[i]);
}
delay(1000);
}
//ISR here
ISR(TIMER1_COMPA_vect)
{
PORTD = Display[Trac];
PORTC = MatCol[Trac];
Trac++;
Trac &= B00000111;
}
//Main loop
void loop()
{
for (int i = 0; i < 8; i++){
Display[i] = ~Display[i];
}
delay(1000);
}
Copy of the .h file
/*
eGamer.h - Library for the eGamer Shield
Created by Brian P Smith, 26.08.11.
*/
#ifndef Egamer_h
#define Egamer_h
#include "WProgram.h"
class Egamer {
public:
void Config(void);
private:
};
#endif
Copy of the .cpp file
/*
eGamer.cpp - Library for the eGamer Shield
Created by Brian P Smith, 26.08.11.
*/
#include "WProgram.h"
#include "Egamer.h"
extern "C"
{
#include <avr/io.h>
#include <avr/interrupt.h>
#include <inttypes.h>
}
void Egamer::Config(void)
{
//Setup ports for the display, buttons, joystick & audio
//PortD = Row data - 76543210
DDRD = B11111111;
//PortC = Column + Buttons - xxCBAxba
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
pinMode(A3, OUTPUT);
pinMode(A4, OUTPUT);
pinMode(A5, OUTPUT);
//PortB = Joystick +6 Audio - xxACuldr
DDRB = B00110000;
//Basic interrupt system
// Disable interrupts while setting registers
cli();
// Reset control registers
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 0;
// Interrupt every 16000000/256/400Hz, 1 column per call
OCR1A = 150;
// Clear Timer on Compare Match (CTC) Mode
bitSet(TCCR1B, WGM12);
// Prescaler x1024
//bitSet(TCCR1B, CS10);
//bitSet(TCCR1B, CS11);
bitSet(TCCR1B, CS12);
// Use system clock for Timer/Counter2
//bitClear(ASSR, AS2);
// Reset Timer/Counter2 Interrupt Mask Register
//TIMSK1 = 0;
// Enable Output Compare Match A Interrupt
bitSet(TIMSK1, OCIE1A);
// Enable interrupts once registers have been updated
sei();
}
Moderator edit: Code boxes instead of quotes to remove spurious italics.