'Serial out to computer

'{$STAMP BS2}
'{$PORT COM1}
' program to illustrate serial communication

' 2 analog inputs provide 2 different values, all of which are
' sent serially to another computer.

' wire two pots with rctime circuits going to pins 9 and 10. ALSO make sure that PROCESSING

' is installed on your computer and has the Etch a Sketch program running

' analog ins are on pins 9, 10
' serial out is on pin 7

 

 

' declare constants:
seroutPin CON 7

pot2Pin CON 9
pot3Pin CON 10
'n9600 con 16624 '9600 8 n 1 for the BSX
n9600 CON 16468 ' use this instead for the BS2

 

 

'declare inputs:

INPUT pot2Pin
INPUT pot3Pin

'declare variables:

pot2Var VAR Word 'first analog in
pot3Var VAR Word 'second analog in

send2Var VAR Byte 'conversion of pot2Var to a byte for sending
send3Var VAR Byte 'conversion of pot3Var to a byte for sending

 

main:

HIGH pot2Pin ' get a value on first input
PAUSE 1
RCTIME pot2Pin, 1, pot2Var

HIGH pot3Pin ' get a value on second input
PAUSE 1
RCTIME pot3Pin, 1, pot3Var

' convert word variables to bytes:

send2Var = ((pot2Var *25)/200) MAX 255
send3Var = ((pot3Var *25)/100) MAX 255

DEBUG DEC pot2Var," ", DEC pot3Var, CR

 

' send information out to the computer:
' first line sends actual byte values:
'SEROUT seroutPin, n9600, [send1var, send2var, send3var, CR]
SEROUT seroutPin, n9600, [send2var, send3var]

'second line sends variables as strings:
'serout seroutPin, n9600, [dec pot1var,",", dec pot2var,",", dec pot3var, 10]
GOTO main