PDA

View Full Version : Simple Button plays a tone



overlook77
05-04-2006, 09:24 AM
I have the StampWorks Kit with the professional development board and a BS2. I am trying to learn the PBASIC language but am having trouble. I want Button 0 to make a sound whenever you press it. However, my code only plays the tone by itself once and the button does nothing. Can someone correct my code?

' {$STAMP BS2}
WkSpace VAR Byte
Main:
BUTTON 8, 1, 0, 0, WkSpace, 1, PlayTone
PlayTone:
FREQOUT 7, 250, 3000

overlook77
05-04-2006, 09:42 AM
Ok, I think I answered my own question...it looks like you have to put the BUTTON command in a loop. Below seems to work.

' {$STAMP BS2}
' {$PBASIC 2.5}


Btn PIN 8

btnWrk VAR Byte

Main:
BUTTON Btn, 0, 200, 20, btnWrk, 0, No_Press
FREQOUT 7, 150, 2000

No_Press:
GOTO Main