how to compile programming code together with condition ?:(
mogu93
Posts: 22
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:
Doesn't it look pretty with code tags?
Instead 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.