I'm really enjoying all that I can do with the Arduino itself and the TVOut Library. But I have a few problems and questions for those with more experience than I have.
I know that you can output sound through the use of "tone" in TVOut, but I'm not certain how to go about it. Whenever I try to do it, only small sounds come out of the speaker and for brief periods of time. They're actually more like small pops that are audible only when a tone starts. Sometimes nothing comes out at all. Everything compiles fine and I'm using the usual format for tone:
tone(pin,frequency,time)
Another question I have is, how can you write the code in a way that tones will play (music or sound effects, etc.) while something else is happening on the screen? I see videos of games developed for arduino with music playing fine along with many different things happening on the screen at once. It makes me wonder what I'm missing. Any help is appreciated!
Well then,
I've taken everything else out of the sketch except for the very basics. Everything to get the TVout running is there, plus a simple tone section in void loop:
I thought so but I'm not sure that I know exactly how it works. All I've seen is that it's coded in the exact same way as the normal tones are. How can the compiler/arduino tell the difference? Can you walk me through the use of the TVout method?
Well I sort of take back my last statement. The sound outputs, but the timing is a bit sluggish and the sound quality is bad. It pops and crackles during the time that it's playing a tone. It may have something to do with the way it's coded. The image on screen also flickers while the tone is played as well. What I'm going for is a motorcycle-like sound that increases in frequency up to a certain number and then resets the frequency (revsound) to a lower value and then it starts a similar loop below it. Is this too much for the Arduino to handle? I wouldn't think so but I still could use some help I guess...
Here's the code:
Doesn't the TVout library have its own version of delay()? Have you tried that instead of the standard delay()? It's less likely to mess with the timing, I would think.
I'm sorry for digging up this old topic but I have the same problem as foxden313002.
The TVOut library plays singles tones just fine. But when it comes to melodies, it sounds choppy.
I am pretty sure that this is because the Uno only has 3 hardware timers and the TVOut library uses all of them to create the video signal using interrupts.
When the Arduino generates a video signal like that, the accuracy of the timing functions is equal to the frame time.
Which results in an accuracy for the "delay()" and "millis()" methods of 16ms(NTSC) or 20ms(PAL).
Even when using the methods that come with the library.
Could this be the cause for the choppy music playback?
And if so, is there any way around that except using a Mega(because it has more timers) or two Unos where one would act as a sound chip?