Shop OBEX P1 Docs P2 Docs Learn Events
Help:controlling the tempo of a song using a potentiometer circuit — Parallax Forums

Help:controlling the tempo of a song using a potentiometer circuit

itsme_melbitsme_melb Posts: 5
edited 2004-12-10 19:27 in Learn with BlocklyProp
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

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-12-10 16:48
    Have a look at the RCTIME instruction. You could use that just before FREQOUT to make an adjustment to the noteDuration variable.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • itsme_melbitsme_melb Posts: 5
    edited 2004-12-10 17:02
    Thank you for the suggestion Jon....should the code look something like this?

    ' ===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
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-12-10 17:38
    Did you try it? You could do that, and it may work fine in your program. Just note that on one end of your program you're going to get very short values. The "typical" RCTIME circuit using a 10K pot and 0.1 uF cap will return values from 0 to about 625. A zero not duration would be a problem. Also, that range I just mentioned is not much higher than your note values. To bump the duration value up to about 900 or so on the high end, and make sure that the low end isn't zero, you could add this after reading the pot:

    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
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2004-12-10 19:27
    Hi Itsme-melb,

    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
Sign In or Register to comment.