Got ethernet working on your code. I can send a single character (r,g,b,i or c). C means full color RGB simultaneous exposure. It changes the exposure time and color channel:
#include <SPI.h>
#include <Dhcp.h>
#include <Dns.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <EthernetServer.h>
#include <EthernetUdp.h>
#include <util.h>
//Serial
int inByte = 0;
//Ethernet
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(198,0,0,4);
EthernetServer* m_server;
EthernetClient m_client;
uint8_t *m_mac_address;
IPAddress m_ip;
int m_port;
char m_command[40];
int m_commandLength;
const byte SHUTTER = 9;
//const byte START_LED = 7;
//const byte END_LED = 8;
const byte RED = 3;
const byte GREEN = 5;
const byte BLUE = 6;
const byte IR = 7;
void setup() {
m_server = new EthernetServer(12345);
// m_mac_address = mac_address;
// m_ip = ip;
// m_port = port;
//Initialize Ethernet Library
Ethernet.begin(mac, ip);
//Start Ethernet Server
m_server->begin();
pinMode (RED, OUTPUT);
pinMode (GREEN, OUTPUT);
pinMode (BLUE, OUTPUT);
pinMode (IR, OUTPUT);
pinMode (SHUTTER, INPUT);
digitalWrite (RED, LOW);
digitalWrite (GREEN, HIGH);
digitalWrite (BLUE, LOW);
digitalWrite (IR, LOW);
digitalWrite (SHUTTER, HIGH);
Serial.begin(9600);
} // end of setup
ISR(TIMER1_COMPA_vect)
{
TCCR1A = 0; // reset timer 1
TCCR1B = 0;
Serial.println("Interrupt Called");
} // end of TIMER1_COMPA_vect
// TCCR1A, TCCR1B
const byte timer_modes [16] [2] =
{
{ 0, 0 }, // 0: Normal
{ _BV (WGM10), 0 }, // 1: PWM, Phase-correct, 8 bit
{ _BV (WGM11), 0 }, // 2: PWM, Phase-correct, 9 bit
{ _BV (WGM10) | _BV (WGM11), 0 }, // 3: PWM, Phase-correct, 10 bit
{ 0, _BV (WGM12) }, // 4: CTC, top = OCR1A
{ _BV (WGM10), _BV (WGM12) }, // 5: Fast PWM, Phase-correct, 8 bit
{ _BV (WGM11), _BV (WGM12) }, // 6: Fast PWM, Phase-correct, 9 bit
{ _BV (WGM10) | _BV (WGM11), _BV (WGM12) }, // 7: Fast PWM, Phase-correct, 10 bit
{ 0, _BV (WGM13) }, // 8: PWM, phase and frequency correct, top = ICR1
{ _BV (WGM10), _BV (WGM13) }, // 9: PWM, phase and frequency correct, top = OCR1A
{ _BV (WGM11), _BV (WGM13) }, // 10: PWM, phase correct, top = ICR1A
{ _BV (WGM10) | _BV (WGM11), _BV (WGM13) }, // 11: PWM, phase correct, top = OCR1A
{ 0, _BV (WGM12) | _BV (WGM13) }, // 12: CTC, top = ICR1
{ _BV (WGM10), _BV (WGM12) | _BV (WGM13) }, // 13: reserved
{ _BV (WGM11), _BV (WGM12) | _BV (WGM13) }, // 14: Fast PWM, TOP = ICR1
{ _BV (WGM10) | _BV (WGM11), _BV (WGM12) | _BV (WGM13) }, // 15: Fast PWM, TOP = OCR1A
};
// timer activation
enum { NO_CLOCK, PRESCALE_1, PRESCALE_8, PRESCALE_64, PRESCALE_256, PRESCALE_1024, CLOCK_T1_FALLING, CLOCK_T1_RISING };
// what ports to toggle on timer fire
enum { NO_PORT = 0,
TOGGLE_ON_COMPARE = _BV (COM1A0),
CLEAR_ON_COMPARE = _BV (COM1A1),
SET_ON_COMPARE = _BV (COM1A0) | _BV (COM1A1) };
// choose a timer mode, set which clock speed, and which port to toggle
void setTimerMode (const byte mode, const byte clock, const byte port)
{
TCCR1A |= (timer_modes [mode] [0]) | port;
TCCR1B |= (timer_modes [mode] [1]) | clock;
} // end of setTimerMode
void FireShutter()
{
TCCR1A = 0; // reset timer 1
TCCR1B = 0;
digitalWrite (SHUTTER, HIGH); // ready to activate
pinMode (SHUTTER, OUTPUT);
switch(m_command[0])
{
case 'r':
digitalWrite (RED, HIGH);
digitalWrite (GREEN, LOW);
digitalWrite (BLUE, LOW);
digitalWrite (IR, LOW);
OCR1A = 50;
break;
case 'g':
digitalWrite (RED, LOW);
digitalWrite (GREEN, HIGH);
digitalWrite (BLUE, LOW);
digitalWrite (IR, LOW);
OCR1A = 500;
break;
case 'b':
digitalWrite (RED, LOW);
digitalWrite (GREEN, LOW);
digitalWrite (BLUE, HIGH);
digitalWrite (IR, LOW);
OCR1A = 5000;
break;
case 'i':
digitalWrite (RED, LOW);
digitalWrite (GREEN, LOW);
digitalWrite (BLUE, LOW);
digitalWrite (IR, HIGH);
break;
case 'c':
digitalWrite (RED, HIGH);
digitalWrite (GREEN, HIGH);
digitalWrite (BLUE, HIGH);
digitalWrite (IR, LOW);
OCR1A = 50000;
break;
}
// set up Timer 1
TCNT1 = 0; // reset counter
// OCR1A = 999; // compare A register value (1000 * clock speed)
setTimerMode (4, PRESCALE_256, CLEAR_ON_COMPARE);
TIFR1 |= _BV (OCF1A); // clear interrupt flag
TIMSK1 = _BV (OCIE1A); // interrupt on Compare A Match
}
void GetCommand()
{
int tempChar;
m_commandLength = 0;
ClearCommand();
do{
if(m_client.available())
{
tempChar = m_client.read();
if(tempChar != 13)
{
m_command[m_commandLength] = tempChar;
m_commandLength += 1;
}
}
}while(tempChar!=13);
m_server->print("OK");
}
void ClearCommand()
{
for(int x=0;x<40;x++)
m_command[x] = 0;
}
void loop() {
m_client = m_server->available();
if(m_client.available())
{
GetCommand();
FireShutter();
}
} // end of loop
So what I need to do is figure out how to get the interrupt to fire. I'll try to code it free of any class stuff. Is it correct that just putting the ISR() function in my header before the class is enough to load the routine into the Arduino? It must be, or your sketch wouldn't work. Here is my original code that worked with my original timer routines:
IN HEADER FILE CLASS DECLARATION:
void (*isrCallback)();
void AttachTimerInterrupt(void (*isr)());
IN .CPP FILE:
ISR(TIMER1_OVF_vect) // interrupt service routine that wraps a user defined function supplied by attachInterrupt
{
led.isrCallback();
}
void LED_V3::AttachTimerInterrupt(void (*isr)())
{
isrCallback = isr; // register the user's callback with the real ISR
TIMSK1 = _BV(TOIE1); // sets the timer overflow interrupt enable bit
TCCR1B |= m_clockSelectBits;
}