I have 9 days before this project has to work, so any help would be greatly appreciated.
I'm pretty sure I know what the problem is, but if there is any way around it, I'd love to know.
I have 2 piezo speakers attached to my Duemilanove, one to pin 12, one to pin 5.
I have 3 transistors controlling external power to LEDs on pins 3, 9 and 10. (all of which are PWM)
I've included the Tone.h library for the speakers, and produce two separate tones simultaneously with them. This works fine.
The LEDs work fine if I use digitalWrite, but don't light at all when I use analogWrite. I know this is due to some interference between the Tone library and the PWM pins, but I would prefer the LEDs to fade on and off, instead of just turn on and off.
If there's any way around this, please let me know.
I have a feeling multiple tones are using the CTC timers on the Duemilanove, though I thought there were three… 2, 1, and 0. And, to my knowledge, 0 is the one responsible for PWM output, so I didn’t expect there to be any conflict.
I wish I could just go with one tone, but unfortunately I require two, but that would probably allow me to regain the fading of the LEDs.
Duemilanove ... sorry I missed that in your original post ... has three timers. Each timer is able to provide PWM on two pins. With the Tone Library, one timer is needed to output on one pin. If the Tone Library has taken control of a timer, that timer is no longer able to provide PWM. To have three PWM pins and two tone pins you need four timers. To make the situation more complicated, the Arduino clock (millis, micros, delay, delayMicroseconds) is driven by timer 0.
You could light each LED at different times with one PWM. You would need 3 transistors (and 3 digital pins). Have the one PWM go to all three positives on the LEDs. Then each LED ground goes through a separate transistor, then to ground. Then activate whichever transistor you want with a separate digital pin.