Help Please
cedtinsi
Posts: 45
Thank you and Welcome
I am having some issues with my code.
The compilation step goes well; but at execution, it is exactly what I do not want.
The Basic Stamp skips everything and executes ' wewillsee1' at the very bottom of the code.
Down below is the code.
I mean when all the pins are not receiving any signal, the Stamp nevertheless executes 'wewillsee1'
I do not get it, please Help.
Thank you.
' {$STAMP BS2}
' {$PBASIC 2.5}
timeCounter VAR Word
Main:
timeCounter=0
PAUSE 4000
timeCounter=timeCounter + 4000
IF (IN2=1) THEN
GOTO wewillsee1
ELSEIF (IN3=1) THEN
GOTO wewillsee1
ELSEIF (IN4=1) THEN
GOTO wewillsee1
ELSEIF ((IN1=1) AND (IN2=1))THEN
GOTO wewillsee1
ELSEIF ((IN1=1) AND (IN3=1) )THEN
GOTO wewillsee1
ELSEIF ((IN1=1) AND (IN4=1))THEN
GOTO wewillsee1
ELSEIF ((IN2=1) AND (IN3=1)) THEN
GOTO wewillsee1
ELSEIF ((IN1=1) AND (IN2=1) AND (IN3=1)) THEN
GOTO wewillsee1
ELSEIF ((IN1=1) AND (IN2=1) AND (IN4=1)) THEN
GOTO wewillsee1
ELSEIF ((IN2=1) AND (IN3=1) AND (IN4=1)) THEN
GOTO wewillsee1
ELSEIF ((IN1=1) AND (IN2=1) AND (IN3=1) AND (IN4=1)) THEN
GOTO wewillsee1
ENDIF
IF (IN1=1) THEN
PAUSE 2000
ELSE
PAUSE 1
END
IF (IN1=1) THEN
IF (IN2=1) THEN
PAUSE 2000
ELSEIF (IN3=1) THEN
GOTO wewillsee2
ELSEIF (IN4=1) THEN
GOTO wewillsee2
ELSE
PAUSE 1
ENDIF
ENDIF
IF (IN1=1)THEN
IF (IN2=1) THEN
IF (IN3=1) THEN
PAUSE 4000
HIGH 15
LOW 14
ELSEIF (IN4=1) THEN
GOTO wewillsee3
ELSE
PAUSE 1
ENDIF
ENDIF
ENDIF
PAUSE 5000
IF (IN1=1)THEN
GOTO wewillsee4
ELSEIF (IN2=1)THEN
GOTO wewillsee4
ELSEIF (IN3=1)THEN
GOTO wewillsee4
ELSEIF (IN4=1)THEN
GOTO wewillsee4
ELSEIF (IN1=1)AND (IN2=1)THEN
GOTO wewillsee4
ELSEIF (IN1=1)AND (IN3=1)THEN
GOTO wewillsee4
ELSEIF (IN1=1)AND(IN4=1)THEN
GOTO wewillsee4
ELSEIF (IN2=1)AND(IN3=1)THEN
GOTO wewillsee4
ELSEIF (IN1=1)AND(IN2=1)THEN
IF (IN3=1)THEN
GOTO wewillsee4
ELSE
IN3=1
GOTO wewillsee4
ENDIF
ELSEIF (IN1=1)AND(IN2=1)THEN
IF (IN4=1)THEN
GOTO wewillsee4
ELSE
IN4=1
GOTO wewillsee4
ENDIF
ELSEIF (IN2=1)AND(IN3=1)THEN
IF (IN4=1)THEN
GOTO wewillsee4
ELSE
IN4=1
GOTO wewillsee4
ENDIF
ELSE
IF (IN1=1)AND(IN2=1)THEN
IF (IN3=1)AND(IN4=1)THEN
GOTO wewillsee4
ENDIF
ENDIF
ENDIF
ENDIF
PAUSE 1000
IF (timeCounter>=9000)THEN
GOTO wewillsee5
ELSE
PAUSE 1
ENDIF
GOTO Main
wewillsee1:
PAUSE 8000
HIGH 13
LOW 12
PAUSE 5000
LOW 13
LOW 12
GOTO Main
END
wewillsee2:
PAUSE 6000
HIGH 13
LOW 12
PAUSE 5000
LOW 13
LOW 12
GOTO Main
END
wewillsee3:
PAUSE 8000
HIGH 13
LOW 12
PAUSE 5000
LOW 13
LOW 12
GOTO Main
END
wewillsee4:
PAUSE 5
HIGH 11
LOW 10
PAUSE 5000
LOW 11
LOW 10
GOTO Main
END
wewillsee5:
PAUSE 1
HIGH 13
LOW 12
PAUSE 5000
LOW 13
LOW 12
GOTO Main
END
I am having some issues with my code.
The compilation step goes well; but at execution, it is exactly what I do not want.
The Basic Stamp skips everything and executes ' wewillsee1' at the very bottom of the code.
Down below is the code.
I mean when all the pins are not receiving any signal, the Stamp nevertheless executes 'wewillsee1'
I do not get it, please Help.
Thank you.
' {$STAMP BS2}
' {$PBASIC 2.5}
timeCounter VAR Word
Main:
timeCounter=0
PAUSE 4000
timeCounter=timeCounter + 4000
IF (IN2=1) THEN
GOTO wewillsee1
ELSEIF (IN3=1) THEN
GOTO wewillsee1
ELSEIF (IN4=1) THEN
GOTO wewillsee1
ELSEIF ((IN1=1) AND (IN2=1))THEN
GOTO wewillsee1
ELSEIF ((IN1=1) AND (IN3=1) )THEN
GOTO wewillsee1
ELSEIF ((IN1=1) AND (IN4=1))THEN
GOTO wewillsee1
ELSEIF ((IN2=1) AND (IN3=1)) THEN
GOTO wewillsee1
ELSEIF ((IN1=1) AND (IN2=1) AND (IN3=1)) THEN
GOTO wewillsee1
ELSEIF ((IN1=1) AND (IN2=1) AND (IN4=1)) THEN
GOTO wewillsee1
ELSEIF ((IN2=1) AND (IN3=1) AND (IN4=1)) THEN
GOTO wewillsee1
ELSEIF ((IN1=1) AND (IN2=1) AND (IN3=1) AND (IN4=1)) THEN
GOTO wewillsee1
ENDIF
IF (IN1=1) THEN
PAUSE 2000
ELSE
PAUSE 1
END
IF (IN1=1) THEN
IF (IN2=1) THEN
PAUSE 2000
ELSEIF (IN3=1) THEN
GOTO wewillsee2
ELSEIF (IN4=1) THEN
GOTO wewillsee2
ELSE
PAUSE 1
ENDIF
ENDIF
IF (IN1=1)THEN
IF (IN2=1) THEN
IF (IN3=1) THEN
PAUSE 4000
HIGH 15
LOW 14
ELSEIF (IN4=1) THEN
GOTO wewillsee3
ELSE
PAUSE 1
ENDIF
ENDIF
ENDIF
PAUSE 5000
IF (IN1=1)THEN
GOTO wewillsee4
ELSEIF (IN2=1)THEN
GOTO wewillsee4
ELSEIF (IN3=1)THEN
GOTO wewillsee4
ELSEIF (IN4=1)THEN
GOTO wewillsee4
ELSEIF (IN1=1)AND (IN2=1)THEN
GOTO wewillsee4
ELSEIF (IN1=1)AND (IN3=1)THEN
GOTO wewillsee4
ELSEIF (IN1=1)AND(IN4=1)THEN
GOTO wewillsee4
ELSEIF (IN2=1)AND(IN3=1)THEN
GOTO wewillsee4
ELSEIF (IN1=1)AND(IN2=1)THEN
IF (IN3=1)THEN
GOTO wewillsee4
ELSE
IN3=1
GOTO wewillsee4
ENDIF
ELSEIF (IN1=1)AND(IN2=1)THEN
IF (IN4=1)THEN
GOTO wewillsee4
ELSE
IN4=1
GOTO wewillsee4
ENDIF
ELSEIF (IN2=1)AND(IN3=1)THEN
IF (IN4=1)THEN
GOTO wewillsee4
ELSE
IN4=1
GOTO wewillsee4
ENDIF
ELSE
IF (IN1=1)AND(IN2=1)THEN
IF (IN3=1)AND(IN4=1)THEN
GOTO wewillsee4
ENDIF
ENDIF
ENDIF
ENDIF
PAUSE 1000
IF (timeCounter>=9000)THEN
GOTO wewillsee5
ELSE
PAUSE 1
ENDIF
GOTO Main
wewillsee1:
PAUSE 8000
HIGH 13
LOW 12
PAUSE 5000
LOW 13
LOW 12
GOTO Main
END
wewillsee2:
PAUSE 6000
HIGH 13
LOW 12
PAUSE 5000
LOW 13
LOW 12
GOTO Main
END
wewillsee3:
PAUSE 8000
HIGH 13
LOW 12
PAUSE 5000
LOW 13
LOW 12
GOTO Main
END
wewillsee4:
PAUSE 5
HIGH 11
LOW 10
PAUSE 5000
LOW 11
LOW 10
GOTO Main
END
wewillsee5:
PAUSE 1
HIGH 13
LOW 12
PAUSE 5000
LOW 13
LOW 12
GOTO Main
END
Comments
What arrangement are you using for your Inputs? Are they pulled low?
Obviously, it's convinced one of your IFs is being satisfied (some INPUT or
combination "= 1").
By placing some DEBUG statements you could tell when/where that occurs.
Why is that?
Nothing in the program tells me that it should do so
The first IF condition is satisfied.
Why?
I checked my circuit as well and pin2 does not receive any current.
"What arrangement are you using for your Inputs? Are they pulled low?"
and got no reply.
My new and improved code, please see attachment.
' {$STAMP BS2}
' {$PBASIC 2.5}
timeCounter VAR Word
'please refer to the attached file for a schematic of the circuit, thank you.
Main:
DO
IF((IN1=1)OR(IN2=1)OR(IN3=1)OR(IN4=1))THEN 'at the beginning of the evaluation, we always want to make sure that all the
'pushbuttons are open; so if only one of them is not open, then we want the blue LED to glow as an indicator to the operator
'that the pushbuttons must be opened before we even begin
'all the wewillsee that you see below end will a goto main statement; this in order to care of this same business
GOTO wewillsee3
ENDIF
LOOP UNTIL ((IN1=0)AND(IN2=0)AND(IN3=0)AND(IN4=0))
PAUSE 4000 'pause for 4 seconds;during this 4 seconds,the operator should have pressed at least one pushbutton
'so that when the if statements bellow are read, one of those conditions gets satisfied and a response is triggered.
' if the operator does not press any during the 4 seconds,then he/she will spend eternity trying to get the right combination
IF (IN2=1)THEN
GOTO wewillsee1 'if the first button pressed by the operator is pushbutton2
'then pause for 6 seconds and red LED glows for 4 seconds and go back to main,we pause for 6 seconds because
'we do not want the operator to guess in any way that the correct combination does not start by pressing pushbutton2
'so we want the total amount of time that ellapses before the operator gets a response, to be approximately the same whether he/she
'is getting the right combination or not
'we will let him joke around for a little bit
ELSEIF (IN3=1)THEN
GOTO wewillsee1 'same thing we want to happen when the first pushbutton pressed is not pushbutton1
ELSEIF (IN4=1)THEN
GOTO wewillsee1
ELSEIF ((IN1=1)AND(IN2=1))THEN 'if after the 4 seconds have ellapsed, the bs2 finds that pushbutton1 and pushbutton2 are pressed
'then we want the bs2 to do go to wewillsee1 as well, because we want to set it up in a way that the operator who knows the correct
'combination of pushbuttons has to know as well that he has 2 seconds to press the next pushbutton after he pressed the first one
'we assumed that the time it takes the bs2 to decide that series of pushbuttons are on ,or pressed, at the same time is very very small
'let us call this very short amount of time, t
'so, the time the operator will take to press a pushbutton after having pressed a previous one-- all this happening during the 2 seconds
' period that we can change at will-- will be greater than max t . you are probably wondering what is the 2 seconds we are talking
'about; keep reading, explanation is just down below
GOTO wewillsee1
ELSEIF ((IN1=1)AND(IN3=1))THEN
GOTO wewillsee1
ELSEIF ((IN1=1)AND(IN4=1))THEN
GOTO wewillsee1
ELSEIF ((IN2=1)AND(IN3=1))THEN
GOTO wewillsee1
ELSEIF ((IN1=1)AND(IN2=1)AND (IN3=1)) THEN
GOTO wewillsee1
ELSEIF ((IN1=1)AND(IN2=1)AND (IN4=1))THEN
GOTO wewillsee1
ELSEIF ((IN2=1)AND(IN3=1)AND (IN4=1))THEN
GOTO wewillsee1
ELSEIF ((IN1=1)AND(IN2=1)AND (IN3=1)AND(IN4=1))THEN
GOTO wewillsee1
ENDIF
IF (IN1=1)THEN 'now, we consider the case of the right combination of pushbuttons; remember,that is pushbutton1 and then 2 and then 3
'we suggest you look at the attached document
PAUSE 2000 'this is the 2 seconds that we talked about earlier, we can adjust it if we judge that we need to increase it a bit
ENDIF
timeCounter = 0
PAUSE 1
timeCounter = timeCounter + 1 'we initialize timeCounter
'the purpose of this timeCounter is to help us know whether or not the 2 seconds pause that follows will take place; knowing whether
'or not it takes place is important to us as we will see shortly
IF (IN1=1)THEN 'verifies that pushbutton1 is still on before testing for pushbutton2
IF (IN2=1)THEN
PAUSE 2000
ELSEIF (IN3=1) THEN
GOTO wewillsee1 'wrong combination of code, red LED must shine
ELSEIF (IN4=1)THEN
GOTO wewillsee1 ' obviously, wrong combination as well
ENDIF
ENDIF
IF timeCounter = 2001 THEN 'helps verify whether or not pushbutton2 has been pressed
IF ((IN1=1)AND (IN2=1)AND (IN3=1))THEN ' at this point, we are sure that if pushbutton1 and 2 and 3 are
'on then we want To have the green LED glow
GOTO wewillsee2
ENDIF
ENDIF
wewillsee1:
PAUSE 6000
HIGH 13
LOW 12
PAUSE 4000
LOW 13
LOW 12
GOTO Main
END
wewillsee2:
PAUSE 6000
HIGH 11
LOW 10
PAUSE 4000
LOW 11
LOW 10
GOTO Main
END
wewillsee3:
PAUSE 6000
HIGH 15
LOW 14
PAUSE 4000
LOW 15
LOW 14
GOTO Main
END
Somehow, one of those pins is at a voltage level that the Stamp thinks is a 1. The traditional way to guard against this is to have each pin "pulled-down" to ground by a high valued resistor, say 47K.
Also, the program will be very hard to debug because of all the long delays. You will never know whether the program is mis-behaving or just waiting.
As has been pointed out several times.....put some DEBUG statements in your program so you know where it is acting up. The other thing to do is to break the program into pieces and test each piece. Start with the first IF statement.
Cheers,
Please insert your codes in the # [code] tags. I suggest (if it is possible) you divide you program code in same different ports and try to debug your code, port by port, from start to end.
Wow. You sir are my hero, I could never have written that bit...... I start drooling after about the third line
Before you blame your program any more, check for resistors in the input lines. Open inputs will "float" giving random states e.g.: 0-1-0-0-0-1-1-............ You have to pull it to ground through a resistor so that with no voltage on the pin it ALWAYS reads ZERO or OFF (Others have mentioned this, I'm just stating the importance)
Electronics 101 - an unconnected pin is floating high. The processor - no surprise here - will read it as true, logic 1, high.
2. Basic program
' {$STAMP BS2e}
' {$PBASIC 2.5}
IF IN1 = 1 THEN
DEBUG ? IN1
ELSE
DEBUG ? IN1
ENDIF
2. Advanced program
' {$STAMP BS2e}
' {$PBASIC 2.5}
IF IN1 THEN
DEBUG ? IN1
ELSE
DEBUG ? IN1
ENDIF
3. A No no program - as originally posted in this thread
Baby steps Bob, baby steps!!!!!
PS PJ - will I get his attention??
For future reference, the preferred attachment for documentation is a PDF file. Many people do not own Microsoft Office, let alone Office 2010. I have Office 2003 and have a converter for 2010 files, but it is not something some people want to download. I'm not sure if Open Office can read them.
A particular thank you to Mr. Stamptrol, I get that I need to create a path to ground for all the 4 pins through a high value resistor.
I will insert some debug statements in the code as well, I fully understand the importance of those.
What I do not get is how to divide the code into pieces and test them individually.
Also, I would appreciate an effective suggestion of yours on how to minimize the delay time of execution of the code.
To Mr. Electrosys,
I appreciate your contribution. I am not good yet, in fact know very little, about partitioning the code to different ports and then debud the code port by port; so, I do not get what you mean.
To Mr. Spiral_72,
Thank for providing me with more emphasis on the importance of placing a ground path, through a high value resistor, for the pins. I got it.
To Mr. Vaclav_sal,
Sure, an unconnected pin is floating high; we got how to fix it.
thanks.
To Mr. Publison
I'm sorry that I did not answer PJ's question, I was busy figuring out what was wrong; later on, I came back to the forum and found out that PJ's question was actually an answer.
thank you to both of you.
Now, how do we minimize the code execution delay? divide the code into pieces and test them individually?
Your asssistance, as always, I say thank you.
pattern = (INL >> 1) & $F
This reads the least significant 8 I/O pins as a group, shifts pins 1-4 into position and masks them off. If other pins are outputs, that's ok since their output state will be read (and ignored). If you used I/O pins 0-3, you could just get the 4 bit value by using INA.
Your complicated IF statement is testing for values where bits 2^1, 2^2, and 2^3 are 1. That includes 8-15, 6, 4, 2. It also tests for some odd values: 3 and 5, but also 7. Eventually, everything but 0 and 1 cause a jump to wewillsee1. Is that really what you want?
You may think I am picking on you, but as stated - the answer is - you do not!
"code execution (delay)" itself is fixed by the processor, however execution of your program is controlled by you.
For example - you may wish to indicate the correct code entered by turining on the LED's for 10 seconds even after the user quit pushing the buttons.
Or you may want ot flash them in some fancy sequece. You are in control here.
As far as modular approach consider this at the begining of you code
' any burned out LED's?
GOSUB CheckLED ' turn each LED on for I second
' LED'OK?
GOSUB AllOK ' print debug "All OK"
' check pushbuttons
GOSUB CheckButtons ' let user push each button and turn on appropriate LED
' all buttons works?
GOSUB AllOK '....
Modular program like one suggested let you reuse your code - subroutine AllOK - and insert another code where necessary without mucking up the works too much.
Also, if you are concerend about maintenance of your program by others - comment like the vote in Chicago - early and often!
A final note - program like yours is a prime cadidate for SELECT and or LOOKUP commands. But that may be too advanced for now.
For now remeber that IF checks for true condition and skips next statement(s) if false.
Cheers Vaclav
I know that you knew I would be back to say that 'I do not understand'
You got me, for I do not get the following:
"Your complicated IF statement is testing for values where bits 2^1, 2^2, and 2^3 are 1. That includes 8-15, 6, 4, 2. It also tests for some odd values: 3 and 5, but also 7. Eventually, everything but 0 and 1 cause a jump to wewillsee1."
And what about that "pattern = (INL >> 1) & $F" ; I do not see anything of the like in the Basic Stamp Manual.
To answer your question: that is not what I want.
I thought that the code I wrote will sense the state of pins 1-4 and raise the digit 1, when a current is getting into the a pin, for that pin; else raise the digit 0.
The same reasoning has been used at page 78 of the "What is a Microcontroller?"
So, how come ?
I mean I am ready to think about this in a different way; but I need you to further asssist me on this.
thank you.
Mr. Vaclav_sal,
Thank you, I will get better on that.
Do you have connections indicated on Page 77 showing 10K pulldown resistors to Vss (Ground)? I don't think that question has been answered yet, but asked many times.
Now, I am trying do understand Mr. green's suggestion on how to speed things up.
Thank you.
This is the code that I tested, as you asked me to.
I went through the manual as well.
The code below does not respond to the presses of any button; so what am I missing?
Thank you.
' {$STAMP BS2}
' {$PBASIC 2.5}
pattern VAR Nib
PAUSE 4000
pattern = (INL >> 1) & $F
DO
IF pattern=%011100000 THEN
HIGH 15
LOW 14
ENDIF
DEBUG "*",CR
LOOP
Any suggestions?
I went into the Stamp Manual and got some information.
' {$STAMP BS2}
' {$PBASIC 2.5}
pattern VAR Nib
DIR3=0
PAUSE 4000
pattern = (INL >> 1) & $F
DO
IF IN3=1 THEN
HIGH 15
LOW 14
ENDIF
DEBUG "*",CR
LOOP
Your 2nd attempt has a mix of what I suggested and what you've been doing already. I don't know why you're making one pin high and the other pin low. If you're trying to produce a pulse, that won't do it.
You clearly have major gaps in your understanding of how a Stamp works and how Parallax Basic works ... all the more reason to start at the beginning of "What's a Microcontroller?" and work through the examples one by one.
Here is a very simple demo that increments the OUTA register, reads the value (INA), then displays the value (DEBUG). Plus this demo show how to break your code up into small chunks. Mike Green is right, you need to take some time to learn and experiment.
I really do appreciate the way you push me to work harder.
Thank you more because you have the answer to every single question I have.
Down below is the new and improved code; * will appear at the debug terminal whenever pattern is 7.
The goal is to set up a 3 digit pin code using 4 pushbuttons; each pushbutton acts as a pin. Pressing the right combination of pushbuttons will, say, open a door.
Using a version of the code below, I am able to open the door, say, if pushbutton 2,3 and 4 are pressed down; but I want to be able to press pushbutton 2, then wait for 2sec and then press pushbutton 3, then wait for 2sec and then press pushbutton 4 before the door get get opened.
the problem is that: when pattern is, say, 4, when pushbutton 2 is pressed, i need to wait the 2sec and ask if pattern is, say, 2 (corresponding to the press of pushbutton 3)... but i do not know how to make the stamp forget for 2sec that pattern was 4 and test pattern anew.
I need you help.
Thank you.
' {$STAMP BS2}
' {$PBASIC 2.5}
pattern VAR Nib
DO
PAUSE 4000
pattern=(IND >> 1)& $F 'gets the state of the last four pins
DEBUG ? pattern, CR ' output to the debug terminal
IF (pattern=7) THEN
DEBUG "*"
ENDIF
LOOP
Typically, your program waits in a loop for the proper combination of buttons to be pushed, then that loop exits. Your program then waits for all buttons to be released (a sort of reset), then there's another loop that waits for another combination of buttons to be pushed, then another wait for the buttons to be released, etc. You might put a time limit in each loop, maybe a count that's decremented by one each time through the loop. When the count reaches zero, there's a goto to the beginning of the program. Try an initial count of 5000 and see how long that takes to "time out". You don't need the "& $F" because IND is already only 4 bits and the shift drops one of those bits. Something like:
You are my man.
You got exactly what I meant.
Once again, this forum is " education to all, for free. "
Thank you, so very much.
Please I would like to know what is the AND NOT operator for all Basic Stamp 2 models.
thanks.
down below is the code that I executed for my four pushbuttons, mentioned in the previous posts.
my code gets stuck at the second do loop; it is as if it cannot execute an IF THEN statement.
Please help me get this.
' {$STAMP BS2}
' {$PBASIC 2.5}
pattern VAR Nib
timeout VAR Word
control VAR Word
beginning:
pattern=IND
DEBUG ? pattern, CR
DO
pattern=IND
DEBUG ? pattern, CR
LOOP UNTIL pattern=8
DO
IF pattern=0 THEN GOTO intern1 ' the code gets stuck here
LOOP
intern1:
timeout=50
DO
pattern=IND
DEBUG ? pattern, CR
timeout=timeout-1
LOOP UNTIL pattern=2
DEBUG SDEC ? timeout
DO
IF ((timeout=0)|(timeout<0)) THEN GOTO beginning
IF (timeout>0) THEN GOTO intern2
LOOP
intern2:
timeout=50
DO
pattern=IND
DEBUG ? pattern, CR
timeout=timeout-1
LOOP UNTIL pattern=1
DEBUG SDEC ? timeout
DO
IF ((timeout=0)|(timeout<0)) THEN GOTO beginning
IF (timeout>0) THEN GOTO intern3
LOOP
intern3:
HIGH 11
LOW 10
PAUSE 1000
LOW 11
LOW 10
down below is the code that I executed for my four pushbuttons, mentioned in the previous posts.
my code gets stuck at the second do loop; it is as if it cannot execute an IF THEN statement.
I did not create an infinite loop, I am sure; because I tried the code, and the intern1 won't even get executed.
Please help me get this.
' {$STAMP BS2}
' {$PBASIC 2.5}
pattern VAR Nib
timeout VAR Word
control VAR Word
beginning:
pattern=IND
DEBUG ? pattern, CR
DO
pattern=IND
DEBUG ? pattern, CR
LOOP UNTIL pattern=8
DO
IF pattern=0 THEN GOTO intern1 ' the code gets stuck here
LOOP
intern1:
timeout=50
DO
pattern=IND
DEBUG ? pattern, CR
timeout=timeout-1
LOOP UNTIL pattern=2
DEBUG SDEC ? timeout
DO
IF ((timeout=0)|(timeout<0)) THEN GOTO beginning
IF (timeout>0) THEN GOTO intern2
LOOP
intern2:
timeout=50
DO
pattern=IND
DEBUG ? pattern, CR
timeout=timeout-1
LOOP UNTIL pattern=1
DEBUG SDEC ? timeout
DO
IF ((timeout=0)|(timeout<0)) THEN GOTO beginning
IF (timeout>0) THEN GOTO intern3
LOOP
intern3:
HIGH 11
LOW 10
PAUSE 1000
LOW 11
LOW 10