Shop OBEX P1 Docs P2 Docs Learn Events
PBasic question — Parallax Forums

PBasic question

CenlasoftCenlasoft Posts: 265
edited 2008-07-14 18:57 in BASIC Stamp
Hello,
I just posted, but failed to explain fully what I wanted to do. I am using a BSII, ADC8031, and tsl253r (light to voltage) sensor. The output is between 0.00 and 4.00. I am sending this to a Parallax lcd module. Below is my code:
As one can see, the output is using serout and producing a string.
My task are:
1.) Add up each reading (ie 2.94) and divide by 10 (average).
2.) I don't know how to convert DEC1 v,".",DEC2 v2,CR to a number inorder to do the math.
3.) Do I have to rewrite the code?
Thanks for your help.
Curtis

' {$STAMP BS2}
' {$PBASIC 2.5}
'
[noparse][[/noparse] Title ]
' Colorimeter Code ADC and TSL253R sensor
' Program Listing 1.0 Revision 10.
'
[noparse][[/noparse] Declarations ]
adcBits········ VAR···· Byte
v·············· VAR···· Byte
r·············· VAR···· Byte
v2············· VAR···· Byte
v3············· VAR···· Byte
counter· VAR Word
'
[noparse][[/noparse] Initialization ]
CS············· PIN···· 0
CLK············ PIN···· 1
DataOutput····· PIN···· 2
DEBUG CLS······································ 'Start display.
'
[noparse][[/noparse] Main Routine ]
'DO
FOR counter = 1 TO 10
· GOSUB ADC_Data
· GOSUB Calc_Volts
· GOSUB Display
NEXT
END
'LOOP
'
[noparse][[/noparse] Subroutines ]
ADC_Data:
· HIGH CS
· LOW CS
· LOW CLK
· PULSOUT CLK, 210
· SHIFTIN DataOutput,CLK,MSBPOST,[noparse][[/noparse]adcBits\8]
RETURN
Calc_Volts:
v = 5 * adcBits / 255
r = 5 * adcBits // 255
v2 = 100 * R / 255
v3 = 100 * r // 255
v3 = 10 * v3 / 255
· IF (v3 >= 5) THEN v2 = v2 + 1
· IF (v2 >= 100) THEN
··· v = v + 1
··· v2 = 0
·ENDIF
RETURN
Display:
SEROUT 10, 16468, [noparse][[/noparse]DEC1 v,".",DEC2 v2,CR]
'DEBUG DEC1 v, ".", DEC2 v2,CR
RETURN

·
Sign In or Register to comment.