how to compile programming code together with condition ?:(
Hi there ,I need help in compiling all the programming code together with some condition as I'm using adc ,speakjet (text to speech ) and basic stamp. At certain voltages it will activate the speakjet to work for announcement purpose.,i will be using the final adc reading at the end to do it . so I need different cases for condition for different announcement .And below is my adc with basic stamp programming thank!
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[ Program Description ]
'
' This program demonstrates reading a variable voltage with an ADC0831
' analog-to-digital converter chip. This program uses a Vref input of
' 5.000 volts (Vdd) for a bit resolution of 19.6 millivolts.
'
[ I/O Definitions ]
CS PIN 0 ' chip select (ADC0831.1)
Clock PIN 1 ' clock (ADC0831.7)
DataIn PIN 2 ' data (ADC0831.6)
'
[ Constants ]
Cnts2Mv CON $139C ' x 19.6 (to millivolts)
'
[ Variables ]
result VAR Byte ' result of conversion
mVolts VAR Word ' millivolts
mVolts1 VAR Word ' millivolts
mVolts2 VAR Word ' millivolts
mVolts3 VAR Word ' millivolts
mVolts4 VAR Word
'
[ Initialization ]
Reset:
DEBUG CLS, ' create report screen
"ADC.... ", CR,
"volts... "
'
[ Program Code ]
Main:
'
'
+
+
'
¦ Initialize ¦
'
+
+
'
' Read the first 3 consecutive ADC values here
GOSUB Read_0831 ' read the ADC
mVolts1 = result */ Cnts2Mv ' convert to millivolts
DEBUG HOME, ' report
CRSRXY, 9, 0, DEC result, CLREOL,
CRSRXY, 9, 1, DEC mVolts1 DIG 3,
".", DEC3 mVolts1
PAUSE 1000
GOSUB Read_0831 ' read the ADC
mVolts2 = result */ Cnts2Mv ' convert to millivolts
DEBUG HOME, ' report
CRSRXY, 9, 0, DEC result, CLREOL,
CRSRXY, 9, 1, DEC mVolts2 DIG 3,
".", DEC3 mVolts2
PAUSE 1000
GOSUB Read_0831 ' read the ADC
mVolts3 = result */ Cnts2Mv ' convert to millivolts
DEBUG HOME, ' report
CRSRXY, 9, 0, DEC result, CLREOL,
CRSRXY, 9, 1, DEC mVolts3 DIG 3,
".", DEC3 mVolts3
PAUSE 1000
'
'
+
+
'
¦ Main Loop ¦
'
+
+
'
'Perpetually read the 4th ADC value here in this loop
DO
GOSUB Read_0831 ' read the ADC
mVolts4 = result */ Cnts2Mv ' convert to millivolts
'
'
+
+
'
¦ Average ¦
'
+
+
'
'Average the 4 ADC results together and display
mVolts = (mVolts1+mVolts2+mVolts3+mVolts4)/4' convert to millivolts
DEBUG HOME, ' report
CRSRXY, 9, 0, DEC result, CLREOL,
CRSRXY, 9, 1, DEC mVolts DIG 3,
".", DEC3 mVolts
PAUSE 3000
'
'
+
+
'
¦ Bump the oldest ADC value out ¦
'
+
+
'
mVolts1=mVolts2
mVolts2=mVolts3
mVolts3=mVolts4
LOOP
Read_0831:
'
'
+
+
'
¦ Read_0831 ¦
'
+
+
'
LOW CS ' enable ADC
SHIFTIN DataIn, Clock, MSBPOST, [result\9] ' read ADC
HIGH CS ' disable ADC
RETURN
' {$PBASIC 2.5}
'
[ Program Description ]
'
' This program demonstrates reading a variable voltage with an ADC0831
' analog-to-digital converter chip. This program uses a Vref input of
' 5.000 volts (Vdd) for a bit resolution of 19.6 millivolts.
'
[ I/O Definitions ]
CS PIN 0 ' chip select (ADC0831.1)
Clock PIN 1 ' clock (ADC0831.7)
DataIn PIN 2 ' data (ADC0831.6)
'
[ Constants ]
Cnts2Mv CON $139C ' x 19.6 (to millivolts)
'
[ Variables ]
result VAR Byte ' result of conversion
mVolts VAR Word ' millivolts
mVolts1 VAR Word ' millivolts
mVolts2 VAR Word ' millivolts
mVolts3 VAR Word ' millivolts
mVolts4 VAR Word
'
[ Initialization ]
Reset:
DEBUG CLS, ' create report screen
"ADC.... ", CR,
"volts... "
'
[ Program Code ]
Main:
'
'
+
+
'
¦ Initialize ¦
'
+
+
'
' Read the first 3 consecutive ADC values here
GOSUB Read_0831 ' read the ADC
mVolts1 = result */ Cnts2Mv ' convert to millivolts
DEBUG HOME, ' report
CRSRXY, 9, 0, DEC result, CLREOL,
CRSRXY, 9, 1, DEC mVolts1 DIG 3,
".", DEC3 mVolts1
PAUSE 1000
GOSUB Read_0831 ' read the ADC
mVolts2 = result */ Cnts2Mv ' convert to millivolts
DEBUG HOME, ' report
CRSRXY, 9, 0, DEC result, CLREOL,
CRSRXY, 9, 1, DEC mVolts2 DIG 3,
".", DEC3 mVolts2
PAUSE 1000
GOSUB Read_0831 ' read the ADC
mVolts3 = result */ Cnts2Mv ' convert to millivolts
DEBUG HOME, ' report
CRSRXY, 9, 0, DEC result, CLREOL,
CRSRXY, 9, 1, DEC mVolts3 DIG 3,
".", DEC3 mVolts3
PAUSE 1000
'
'
+
+
'
¦ Main Loop ¦
'
+
+
'
'Perpetually read the 4th ADC value here in this loop
DO
GOSUB Read_0831 ' read the ADC
mVolts4 = result */ Cnts2Mv ' convert to millivolts
'
'
+
+
'
¦ Average ¦
'
+
+
'
'Average the 4 ADC results together and display
mVolts = (mVolts1+mVolts2+mVolts3+mVolts4)/4' convert to millivolts
DEBUG HOME, ' report
CRSRXY, 9, 0, DEC result, CLREOL,
CRSRXY, 9, 1, DEC mVolts DIG 3,
".", DEC3 mVolts
PAUSE 3000
'
'
+
+
'
¦ Bump the oldest ADC value out ¦
'
+
+
'
mVolts1=mVolts2
mVolts2=mVolts3
mVolts3=mVolts4
LOOP
Read_0831:
'
'
+
+
'
¦ Read_0831 ¦
'
+
+
'
LOW CS ' enable ADC
SHIFTIN DataIn, Clock, MSBPOST, [result\9] ' read ADC
HIGH CS ' disable ADC
RETURN

Comments
There's a tutorial on posting code to the forum at the link below.
Take a look at the program "SELECT-CASE.BS2" in the sample programs that come with the BS editor. It looks like it has an example of doing what you want.
It was part of the software installation.
Here it is:
' SELECT-CASE.BS2' This program generates a series of 16-bit random numbers and tests each ' to determine odd or even, and where it falls in the possible range: ' lower third, middle third, or upper third. The program is useful for ' testing various seed values for RANDOM. ' {$STAMP BS2} ' {$PBASIC 2.5} test VAR Byte ' counter for tests sample VAR Word ' random number to be tested odd VAR Byte ' odd throws even VAR Byte ' even throws isLo VAR Byte ' sample in lower third isMid VAR Byte ' in middle thrid isHi VAR Byte ' in upper third Main: sample = 11000 ' initialize seed FOR test = 1 TO 100 ' "throw" 100 times RANDOM sample ' randomize IF (sample.BIT0) THEN ' check odd/even bit odd = odd + 1 ' increment odd count ELSE even = even + 1 ' increment even count ENDIF SELECT sample CASE <= 21845 ' test lower third isLo = isLo + 1 CASE 21846 TO 43691 ' test middle third isMid = isMid + 1 CASE ELSE ' otherwise upper third isHi = isHi + 1 ENDSELECT NEXT Show_Results: DEBUG CLS, "Odd Throws.... ", DEC odd, "%", CR, "Even Throws... ", DEC even, "%", CR, "Low........... ", DEC isLo, "%", CR, "Mid........... ", DEC isMid, "%", CR, "High.......... ", DEC isHi, "%", CR ENDDoesn't it look pretty with code tags?
SELECT sample CASE <= 21845 ' test lower third isLo = isLo + 1 CASE 21846 TO 43691 ' test middle third isMid = isMid + 1 CASE ELSE ' otherwise upper third isHi = isHi + 1 ENDSELECTInstead of "sample" you'd use your voltage reading. You'd then make each case a range of readings with a message to display for each case.