Help:controlling the tempo of a song using a potentiometer circuit
itsme_melb
Posts: 5
I have question...How can I use a potentiometer circuit to control the tempo of this program. Any suggestions or hints would be great....I'm not great at coding...I need some direction...
Here is the code for the program so far(this plays the first seven notes of twinkle twinkle little star):
Notes DATA "C", "C", "G", "G", "A", "A", "G"
Frequencies DATA Word 2093, Word 2093, Word 3136, Word 3136,
Word 3520, Word 3520, Word 3136
Durations DATA Word 500, Word 500, Word 500, Word 500,
Word 500, Word 500, Word 1000
index VAR Nib
noteLetter VAR Byte
noteFreq VAR Word
noteDuration VAR Word
DEBUG "Note Duration Frequency", CR,
"----
", CR
FOR index = 0 TO 6
READ Notes + index, noteLetter
DEBUG " ", noteLetter
READ Durations + (index *2), Word noteDuration
DEBUG " ", DEC4 noteDuration
READ Frequencies + (index * 2), Word noteFreq
DEBUG " ", DEC4 noteFreq, CR
FREQOUT 9, noteDuration, noteFreq
NEXT
END
Post Edited (itsme_melb) : 12/10/2004 4:27:02 PM GMT
Here is the code for the program so far(this plays the first seven notes of twinkle twinkle little star):
Notes DATA "C", "C", "G", "G", "A", "A", "G"
Frequencies DATA Word 2093, Word 2093, Word 3136, Word 3136,
Word 3520, Word 3520, Word 3136
Durations DATA Word 500, Word 500, Word 500, Word 500,
Word 500, Word 500, Word 1000
index VAR Nib
noteLetter VAR Byte
noteFreq VAR Word
noteDuration VAR Word
DEBUG "Note Duration Frequency", CR,
"----
", CR
FOR index = 0 TO 6
READ Notes + index, noteLetter
DEBUG " ", noteLetter
READ Durations + (index *2), Word noteDuration
DEBUG " ", DEC4 noteDuration
READ Frequencies + (index * 2), Word noteFreq
DEBUG " ", DEC4 noteFreq, CR
FREQOUT 9, noteDuration, noteFreq
NEXT
END
Post Edited (itsme_melb) : 12/10/2004 4:27:02 PM GMT
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
' ===Main Routine====
FOR index = 0 TO 6
READ Notes + index, noteLetter
DEBUG " ", noteLetter
READ Durations + (index *2), Word noteDuration
DEBUG " ", DEC4 noteDuration
READ Frequencies + (index * 2), Word noteFreq
DEBUG " ", DEC4 noteFreq, CR
HIGH 7
PAUSE 10
RCTIME 7, 1, noteDuration
FREQOUT 9, noteDuration, noteFreq
NEXT
END
noteDuration = (noteDuration */ $180) MIN 100
The '*/ $180' part is the same as multiplying noteDuration by 1.5 -- PBASIC style. And the MIN operater prevents the sound from playing so fast that it's unintelligible.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
In the program you have, the RCtime value is simply replacing the note durations, and I don't think that is what you want. The value from RCTIME should go into its own variable, which should then scale the note durations that you read from the eeprom. That will change the overall tempo.
RCTIME 7, 1, scaleFactor ' a word variable
HIGH 7 ' put this after RCTIME so you don't need the 10ms delay.
FREQOUT 9, noteDuration */ scalefactor, noteFreq ' scale applied to all durations.
That will work best if you choose the RC so that the scaleFactor falls in the range of 60 to 1000. That would give you a 16:1 range of tempos. For example, a 10kohm potentiometer in series with a 1kohm fixed resistor, feeding a 0.033uF capacitor should put it in about the right range.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com