InterActive 2
Interactive 2
This is an explanation of the code for the flow control I came up with it to get my Basic Stamp 2(BS2) talking to my Basic Stamp 1(BS1). I am showing the main loops only. For the code files look at letsmakerobots.com and here. Files or a zip file.
In my code I use a lot of Bit flags. Most processors allow access to the Bits of a Byte or Word to use like regular variables. Basic Stamp 1 and most Picaxe processors have defined variable names for the Bits of first few bytes of memory. Usually it is Bit0 – Bit7 or Bit0 – B15 or Bit0 – Bit31 to define a variable. In both of these processors the variable Bits can also be in another variable. Like my lights Byte B0 the Bits are the variables Bit0 – 7 that are lit1 – lit8 the individual lights. This makes testing of a light easy. “If lit1 = 1 then litOn” is simple.
The Basic Stamp 2 and processors like it use defined subscripting to access the Bits, Nibbles and Bytes of a variable. My individual lights are the variables “lights.Bit0 - Bit7”. In testing a variable Bit is “if lghts.Bit0 = 1 then litOn”. Setting is “litTmp = lights.Bit0”. Usually the subscripts can not be a variable. Look at the program files in the EasyLights article. Read your manual.
I fixed as much as I could. The BS1 doesn’t do serial out very well. It is stable and runs like any simple button on a system like this. The BS1 doesn’t do Bits very well either.
My flow control is the only way I got these systems to communicate.
My text comments will be // in this article. In Basic Stamp code the ' is a comment.
//Basic Stamp 2 code fragment.
jp6:
'Basic Stamp 1 Project board(BS1Pj1)
'Incomming message
slv1In = 0
LOW sTx 'Message Acknowledge
PAUSE 6
//Lead in Pause
SERIN slvRx, 396, 350, err1, [slv1Stat, tmp1]
//Serial error time to wait and error handler
PAUSE 3
HIGH sTx
'The BS1 doesn't do serial very well.
IF slv1Stat = 10 THEN jp7
IF slv1Stat = 20 THEN jp9
//I get nothing but errors ??????
errSlv1 = 0
slv1btn2 = 0
GOTO jp2
err1:
DEBUG "Error Stat ", DEC slv1Stat, ", B", BIN slv1Stat, CR
DEBUG "Error tmp", DEC tmp1, ", B", BIN tmp1, CR
IF slv1Stat = 10 THEN jp7
IF slv1Stat = 20 THEN jp9
errSlv1 = 1
slv1btn2 = 0
GOTO jp2
jp9:
'Work in progress
DEBUG "Btn2 ", DEC slv1Stat, ", B", BIN slv1Stat, CR
slv1btn2 = 1
GOTO jp2
jp7:
binSet = 1
ranSet = 1
larset = 1
rMode = rMode + 1
IF rMode < 4 THEN jp2
rMode = 1
'Transmit Section
jp2:
IF sRx = 0 THEN slv1In = 1 'Checks for messages
IF pRx = 0 THEN mstIN = 1 'Checks for messages
IF litSet = 1 THEN jp3
IF mastSet = 1 THEN jp4
'BS1Pj1 can only get hit 1 in 10 times
cnt2 = cnt2 + 1
IF sRx = 0 THEN slv1In = 1
IF cnt2 < 10 THEN jp1
cnt2 = 1
'Control for EasyLights on BS2Pj1
jp4:
SELECT rMode
CASE 1
GOSUB doLarson
CASE 2
GOSUB doBinNum
CASE 3
GOSUB doRandom
ENDSELECT
'Send the lights byte to BS1Pj1 for display
LOW lit1
LOW sTx 'Signals Message Ready
PAUSE 80 'For BS1Pj1
SEROUT slvTx, 396, [BS1Pj1, lights]
PAUSE 40
HIGH sTx
HIGH lit1
litSet = 1
……………………………………………
Basic Stamp 1 code
runIt: 'Buttons one at a time
IF BS1Stat > 0 THEN run2
IF pBtn1 = 0 THEN bt2
BS1Stat = 10
GOTO bt3
bt2:
IF pBtn2 = 0 THEN run2
BS1Stat = 20
bt3:
tmp1 = 66
pTx = litOff
run1: 'Send button message
PAUSE 1 'Wait for master to lower its Tx
IF pRx = 1 THEN run1
SEROUT pinTx, T2400, (tmp1, BS1Stat)
PAUSE 1
pTx = litOn
GOTO jp1
run2:
IF pRx = 1 THEN jp1 'Check for message
SERIN pinRx, T2400, mCmd, tmp1
PAUSE 3
IF mCmd <> BS1Pj1 THEN jp1 'Check for correct address
lights = tmp1
'Do lights onto EasyLights
This is an explanation of the code for the flow control I came up with it to get my Basic Stamp 2(BS2) talking to my Basic Stamp 1(BS1). I am showing the main loops only. For the code files look at letsmakerobots.com and here. Files or a zip file.
In my code I use a lot of Bit flags. Most processors allow access to the Bits of a Byte or Word to use like regular variables. Basic Stamp 1 and most Picaxe processors have defined variable names for the Bits of first few bytes of memory. Usually it is Bit0 – Bit7 or Bit0 – B15 or Bit0 – Bit31 to define a variable. In both of these processors the variable Bits can also be in another variable. Like my lights Byte B0 the Bits are the variables Bit0 – 7 that are lit1 – lit8 the individual lights. This makes testing of a light easy. “If lit1 = 1 then litOn” is simple.
The Basic Stamp 2 and processors like it use defined subscripting to access the Bits, Nibbles and Bytes of a variable. My individual lights are the variables “lights.Bit0 - Bit7”. In testing a variable Bit is “if lghts.Bit0 = 1 then litOn”. Setting is “litTmp = lights.Bit0”. Usually the subscripts can not be a variable. Look at the program files in the EasyLights article. Read your manual.
I fixed as much as I could. The BS1 doesn’t do serial out very well. It is stable and runs like any simple button on a system like this. The BS1 doesn’t do Bits very well either.
My flow control is the only way I got these systems to communicate.
My text comments will be // in this article. In Basic Stamp code the ' is a comment.
//Basic Stamp 2 code fragment.
jp6:
'Basic Stamp 1 Project board(BS1Pj1)
'Incomming message
slv1In = 0
LOW sTx 'Message Acknowledge
PAUSE 6
//Lead in Pause
SERIN slvRx, 396, 350, err1, [slv1Stat, tmp1]
//Serial error time to wait and error handler
PAUSE 3
HIGH sTx
'The BS1 doesn't do serial very well.
IF slv1Stat = 10 THEN jp7
IF slv1Stat = 20 THEN jp9
//I get nothing but errors ??????
errSlv1 = 0
slv1btn2 = 0
GOTO jp2
err1:
DEBUG "Error Stat ", DEC slv1Stat, ", B", BIN slv1Stat, CR
DEBUG "Error tmp", DEC tmp1, ", B", BIN tmp1, CR
IF slv1Stat = 10 THEN jp7
IF slv1Stat = 20 THEN jp9
errSlv1 = 1
slv1btn2 = 0
GOTO jp2
jp9:
'Work in progress
DEBUG "Btn2 ", DEC slv1Stat, ", B", BIN slv1Stat, CR
slv1btn2 = 1
GOTO jp2
jp7:
binSet = 1
ranSet = 1
larset = 1
rMode = rMode + 1
IF rMode < 4 THEN jp2
rMode = 1
'Transmit Section
jp2:
IF sRx = 0 THEN slv1In = 1 'Checks for messages
IF pRx = 0 THEN mstIN = 1 'Checks for messages
IF litSet = 1 THEN jp3
IF mastSet = 1 THEN jp4
'BS1Pj1 can only get hit 1 in 10 times
cnt2 = cnt2 + 1
IF sRx = 0 THEN slv1In = 1
IF cnt2 < 10 THEN jp1
cnt2 = 1
'Control for EasyLights on BS2Pj1
jp4:
SELECT rMode
CASE 1
GOSUB doLarson
CASE 2
GOSUB doBinNum
CASE 3
GOSUB doRandom
ENDSELECT
'Send the lights byte to BS1Pj1 for display
LOW lit1
LOW sTx 'Signals Message Ready
PAUSE 80 'For BS1Pj1
SEROUT slvTx, 396, [BS1Pj1, lights]
PAUSE 40
HIGH sTx
HIGH lit1
litSet = 1
……………………………………………
Basic Stamp 1 code
runIt: 'Buttons one at a time
IF BS1Stat > 0 THEN run2
IF pBtn1 = 0 THEN bt2
BS1Stat = 10
GOTO bt3
bt2:
IF pBtn2 = 0 THEN run2
BS1Stat = 20
bt3:
tmp1 = 66
pTx = litOff
run1: 'Send button message
PAUSE 1 'Wait for master to lower its Tx
IF pRx = 1 THEN run1
SEROUT pinTx, T2400, (tmp1, BS1Stat)
PAUSE 1
pTx = litOn
GOTO jp1
run2:
IF pRx = 1 THEN jp1 'Check for message
SERIN pinRx, T2400, mCmd, tmp1
PAUSE 3
IF mCmd <> BS1Pj1 THEN jp1 'Check for correct address
lights = tmp1
'Do lights onto EasyLights