Shop OBEX P1 Docs P2 Docs Learn Events
The Musical PWMPAL — Parallax Forums

The Musical PWMPAL

hitswarehitsware Posts: 156
edited 2007-04-14 20:41 in BASIC Stamp
Seems to work great [noparse]:)[/noparse]
Way less pops than 'freqout'

C maj scale:

SEROUT 0,6,[noparse][[/noparse]"!PWMSS",240] ' initialize outputs
ck CON 3600 ' set key of scale
cl CON 48:dl CON 54:el CON 60:fl CON 64 ' set ratios of note
gl CON 72:al CON 80:bl CON 90:ch CON 96 ' frequencies in major scale
dr VAR byte:x VAR nib:fr VAR byte ' set variables
FOR x= 0 to 7 ' start scale
LOOKUP x,[noparse][[/noparse]cl,dl,el,fl,gl,al,bl,ch],fr ' find notes
dr=ck/fr ' calculate duration from frquency
SEROUT 0,6,[noparse][[/noparse]"!PWMM1",dr,0,dr,0] ' play note
PAUSE 400 ' set time for each note
NEXT ' goto next note
SEROUT 0,6,[noparse][[/noparse]"!PWMSS",0] ' turn off all channels
END
Sign In or Register to comment.