Going to a Mega board will be a real adventure, I'm thinking. Since I haven't had the "opportunity" to test a Wave Shield with any of the wave player software libraries, I can't say how compatible they might be with a Mega board
Many Arduino pins have different physical port positions, so if the library uses direct port pin manipulation, the library functions might have to be changed. The SPI port pins are different, so getting the SD memory module to operate on a Wave Shield plugged into a Mega board (or a Mega proto shield that is plugged into a Mega board) may require some minor surgery (or, maybe, not). Etc., etc.
Just as a teaser: Forget the wave stuff for now. Let's just see what we can do with IRremote.
I have been thinking of porting the IRremote library to use with my Metga1280 board, but I haven't done anything until now. I haven't really needed such a thing, but, it has crossed my mind...
So, I'll get started like this:
First of all, as we already know, the IRremote library as supplied uses Timer 2 and the IR transmit output is the ATmega OC2B pin.
Now, here's where it starts to get a little bit "interesting."
For the ATmega328p, OC2B is Bit 3 on PORT D (Pin 5 on the 28-pin DIP package). For Arduino boards using '328 processors, Pin D3 is connected to Arduino Pin 3. So, with the original package, if you connect your transmit LED circuitry to Arduino Pin 3 you are in business.
However...
For the ATmega1280 and '2560 chips, OCR2B is connected to Bit 6 of Port H (pin 18 of the 100 TQFP package). On the Mega boards, Pin H6 is connected to Arduino Pin 9.
So, to get the IRremote send functions to work on a Mega board, open IRremote.cpp and go to the lines where it sets the pin mode of pin 3 to output (line 200, I think).
Change the code in line 200 and 201 to the following:
//
// For Mega boards, OCR2B is Arduino Pin 9. For '328 boards it's Arduino Pin 3
// davekw7x
//
#if defined (__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
pinMode(9, OUTPUT);
digitalWrite(9, LOW); // When not sending PWM, we want it low
#else
pinMode(3, OUTPUT);
digitalWrite(3, LOW); // When not sending PWM, we want it low
#endif
Now, this is just a beginning: You have a library for which the transmit stuff works with '328 Arduino boards and Mega boards. The difference is that for '328 boards you put the transmit circuitry on pin 3 and with Mega boards you put it on pin 9.
If Pin 9 is OK for your application (no conflicts with your wave player or other applications), you are finished with the IRremote library. You can skip over the
stuff about changing IRremote to use another Timer____________
Start of stuff about changing IRremote to use another Timer___________
So...
Make sure the IRremote stuff (transmitting and receiving) works before going any farther. Note that I have tested the transmit part, but not the receive part. I "think" the receive stuff might work, and some day I will test it.
Now, the biggie: Instead of Timer 2, I will try the '1280 Timer 4. Timer 4 is somewhat "enhanced" over Timer 2, but has modes that are compatible with what the IRremote uses to create the transmit timing.
So, make the changes that I showed before, except use pin 79in the setMode and digitalWrite statements.
Now, here's the "fun" stuff: Everywhere in IRremote.cpp that it uses Timer 2 registers, change the statements to use Timer 4. (If you are using the Arduino IDE text editor, now might be a good time to get a "real" programmer's editor, but you can probably do it with the built-in editor....)
For one example: In the IRsend::mark function, instead of
TCCR2A |= _BV(COM2B1);
We want
TCCR4A |= _BV(COM4B1); // Enable Mega pin 7 PWM output
Maybe put the #if defined... stuff around two statements like this:
#if defined (__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
TCCR4A |= _BV(COM4B1); // Enable Mega Pin 7 PWM output
#else
TCCR2A |= _BV(COM2B1); // Enable Duelimanove/UNO PWM Pin 3 output
#endif
And so it goes...
If you have changed everything concerning Timer 2 and its registers to Timer 4, you should be ready to start testing. (You will have to define a macro for RESET_TIMER4 in IRremoteInt.h to be able to use it in IRremote.cpp.)
____________
End of stuff about changing IRremote to use another Timer___________
Then...After you are absolutely positively sure that all of the IRremote stuff works with your Mega (again, I have tested the IR transmit stuff but not the receiver stuff with my changes), you are ready to start with the WaveHC library. It can still use Timer 1, but you will have to make changes for the different pin numbers in some of the functions. I'll leave that up to you.
Regards,
Dave