Getting "BUTTON" to work
My BS1 system should beep once at startup and then wait until a button is pressed. Then, it should continuously beep.
Right now, with the below code, the piezo just turns on (the switch is off - it should only turn on when the switch if first turned on):
I also tried changing this line:
to this line:
The result is the same [noparse]:([/noparse]
Help would be appreciated!!! Thanks!!
Right now, with the below code, the piezo just turns on (the switch is off - it should only turn on when the switch if first turned on):
Main:
HIGH 3
PAUSE 250
LOW 3
goin = 0
GOTO Try
Try:
FOR reps = 1 TO 0
HIGH CS ' Deactivate the ADC to begin.
GOSUB Convert
grnd = AD*1
GOSUB Convert ' Get data from ADC.
prev= AD
BUTTON Btn, 4, 200, 20, btnWrk, 1, Again
NEXT
Again:
HIGH 3
I also tried changing this line:
BUTTON Btn, 4, 200, 20, btnWrk, 1, Again
to this line:
BUTTON Btn, 4, 200, 20, btnWrk, 0, Again
The result is the same [noparse]:([/noparse]
Help would be appreciated!!! Thanks!!

Comments
FOR reps = 1 TO 0? Where is your Convert subroutine? It seems there is code missing...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
Is this wrong?
Should I just call GOTO Try instead?
Thanks!
It may be in infinte loop in some variants of BASIC, but not in PBASIC. Take a look at the LOOP command, or use the GOTO as you suggested.
Regards,
Bruce Bates
I want it to only activate one time when the button is first pressed, and then not concern itself with the button again.
Here's the code:
What's wrong?
Thanks!
Until you can post the completed code I doubt you’re going to get any better answers. I don’t even see how that code could compile since your Convert subroutine is missing and the code seems to END at the HIGH 3 command.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
So... is my BUTTON code correct? I want it to execute Again, which calls itself forever (until apogee is reached). Once button executes once, it should be ignored.
Thanks!
Post Edited (ghost13) : 6/13/2007 6:06:08 AM GMT
Thanks!
Here is the full code:
' {$STAMP BS1} ' {$PBASIC 1.0} 'Vars for ADC input SYMBOL CS = 0 ' Chip select; 0 = active. SYMBOL CLK = 1 ' Clock to ADC; out on rising, in on falling edge. SYMBOL DIO_n = 2 ' Pin _number_ of data input/output. SYMBOL DIO_p = PIN2 ' Variable_name_ of data input/output. SYMBOL ADbits = B1 ' Counter variable for serial bit reception. SYMBOL AD = W1 ' 12-bit ADC conversion result. SYMBOL sglDif = 1 ' Single-ended, two-channel mode. SYMBOL msbf = 1 ' Output 0s after data transfer is complete. SYMBOL oddSign = BIT0 ' Program writes channel # to this bit. 'other vars: SYMBOL reps = B2 ' counter for infinite loop SYMBOL lastRead= W2 ' for check if after apogee SYMBOL grnd= W3 ' base reading everything is based off of SYMBOL prev= W4 ' base reading everything is based off of 'for beeping: SYMBOL i = B3 SYMBOL ioByte = B2 SYMBOL Btn = 0 SYMBOL btnWrk = B4 SYMBOL pos = B4 SYMBOL G_SWITCH = PIN4 'the main part of the program LOW 7 HIGH 3 PAUSE 500 LOW 3 INPUT G_SWITCH Check: IF G_SWITCH=0 THEN Check HIGH CS ' Deactivate the ADC to begin. GOSUB Convert grnd = AD prev= grnd lastRead = prev Again: HIGH 3 ' infinite loop GOSUB Convert lastRead = AD prev = prev+5 IF lastRead>prev THEN Pyro ' display if after apogee prev = lastRead ' Change input channels. GOTO Again ' Endless loop. Pyro: HIGH 3 PAUSE 2000 LOW 3 HIGH 7 PAUSE 3000 LOW 7 lastRead=grnd-lastRead lastRead=3346-lastRead Disp: GOSUB Long GOSUB Medium ioByte = lastRead/1000 'get 1000s GOSUB Play_Number GOSUB Medium ioByte = lastRead//1000/100 'get 100s GOSUB Play_Number GOSUB Medium ioByte = lastRead//100/10 'get 10s GOSUB Play_Number GOSUB Medium ioByte = lastRead//10 'get 1s GOSUB Play_Number GOSUB Medium GOTO Disp Play_Number: IF ioByte = 0 THEN Change GOSUB PN RETURN PN: FOR i = 1 TO ioByte 'one "beep" per count GOSUB Short NEXT PAUSE 250 RETURN Change: ioByte = 10 GOSUB PN ioByte = 0 RETURN Short: HIGH 3 PAUSE 300 LOW 3 PAUSE 150 RETURN Medium: PAUSE 500 RETURN Long: HIGH 3 PAUSE 1250 LOW 3 PAUSE 500 RETURN 'the conversion subroutine: Convert: LOW CLK ' Low clock--output on rising edge. HIGH DIO_n ' Switch DIO to output high (start bit). LOW CS ' Activate the 1298. PULSOUT CLK,5 ' Send start bit. LET DIO_p = sglDif ' First setup bit. PULSOUT CLK,5 ' Send bit. LET DIO_p = oddSign ' Second setup bit. PULSOUT CLK,5 ' Send bit. LET DIO_p = msbf ' Final setup bit. PULSOUT CLK,5 ' Send bit. INPUT DIO_n ' Get ready for input from DIO. LET AD = 0 ' Clear old ADC result. FOR ADbits = 1 TO 13 ' Get null bit + 12 data bits. LET AD = AD*2+DIO_p ' Shift AD left, add new data bit. PULSOUT CLK,5 ' Clock next data bit in. NEXT ' Get next data bit. HIGH CS ' Turn off the ADC RETURN ' Return to program.▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support