Shop OBEX P1 Docs P2 Docs Learn Events
how to play music continuously? — Parallax Forums

how to play music continuously?

nowhatevenowhateve Posts: 8
edited 2008-11-28 23:45 in BASIC Stamp
i got a demo code online emitting some kind of music. however, it does not last long. how could i make it play it continuously? the code is pasted below.

'========================================================================
'{$STAMP BS2} 'STAMP directive (specifies a BS2)
'
i VAR BYTE ' Counter for position in tune.
f VAR WORD ' Frequency of note for FREQOUT.
C CON 2092 ' C note
D CON 2348 ' D note
E CON 2636 ' E note
G CON 3136 ' G note
R CON 0 ' Silent pause (rest).
'
FOR i = 0 TO 28 ' Play the 29 notes of the LOOKUP table.
LOOKUP i,[noparse][[/noparse]E,D,C,D,E,E,E,R,D,D,D,R,E,G,G,R,E,D,C,D,E,E,E,E,D,D,E,D,C],f
FREQOUT 11,225,f,(f MIN 8) - 8
NEXT
STOP
'========================================================================

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-11-28 20:23
    What do you think? Hint: Look at the description of the STOP statement in the manual.

    If you can't figure it out, then download the "What's a Microcontroller?" tutorial from here www.parallax.com/tabid/535/Default.aspx and begin to work through the exercises so you can learn how to program.
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-11-28 21:53
    Above the "FOR", add a label (like "MAIN:")

    After the "NEXT", add a GOTO statement (like "GOTO MAIN")

    You'll then have an "Infinite Loop", which is what you want for continuous music in this case. It will repeat forever (or until you turn the power off) whichever happens first.
  • JDJD Posts: 570
    edited 2008-11-28 23:45
    nowhateve,

    There are various ways to program this routine; however·our What's A Microcontroller teaches how to program DO...LOOP and GOSUB commands for this task.·These are two commands that you would rarely encounter·a loop·the program·can not get out of.

    Along with the What's A Microcontroller, you can download the BASIC Stamp Syntax & Reference Manual to help explain how to use the various types of commands and·provides some example code to help;·a reference I'm sure both Mike and Allen would agree any BASIC Stamp programmer should have.

    I hope these ideas help, and I'm sure if you review the free educational texts they will.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Joshua Donelson

    www.parallax.com
Sign In or Register to comment.