look back ? Help

1968neil

Senior Member
Hi Guys,

Have a minor problem that i cant get my head round.
If you look at the attached code in the last loop "keepalive" i need the code to sit in that loop until the switch is pressed again.

any suggestions or am i missing something basic ?

Regards

Neil

The code:

symbol led = 4
symbol op1 = 1
symbol op2 = 2
symbol pbswitch = pin3
symbol down = 0

symbol counter = b0

counter = 0 'initialise counter

loop1:
if pbswitch = down then switchdown ' is switch pressed
branch counter, (talkthruoff, talkthruon) 'branch on counter state
counter = 0 'reset counter
goto loop1

switchdown:
counter = counter + 1 'Increment counter

sdloop:
if pbswitch = down then sdloop ' wait til switch released
goto loop1

talkthruoff:
low led
low op1
high op2
pause 500 'wait 500ms
high 0 'output high on 0
pause 250 'wait 250ms
low 0 'output low on 0
goto loop1

talkthruon:
high led 'led on
high op1 'op1 on
low op2 'op2 off
goto keepalive

keepalive:

high 0
pause 1000
low 0

goto loop1
 

BeanieBots

Moderator
Lots of "goto"s and most seem to go back to loop1.

Have a look at the do/loop structure. It might make your life easier.

Do
'some code here which continually gets executed until the switch is pressed
Loop until switch = down


do
'some other code here which gets executed until the switch is released
Loop until switch <> down 'exit loop when switch released
 

tiscando

Senior Member
while TC = online

do
'some other code here which gets executed while the switch is pressed
Loop while switch = down 'loop back if switch is still pressed

Let's make some use of 'while', should we?
 

vttom

Senior Member
Is this what you're looking for?

Code:
keepalive:

do
  high 0 
  pause 1000
  low 0
loop until pbswitch = down

goto loop1
Or possibly:

Code:
keepalive:

do
  high 0 
  pause 1000
  low 0
loop until pbswitch = down

do
loop while pbswitch = down

goto loop1
 
Top