Basic Emergency Stop

novolts

Senior Member
Hi All
I have come to the decision that I will always be a picaxe basic command user and most of the time I will struggle with basic commands

I have copied the following from the basic command manual and still I struggle

I have copied this code from the clipboard app in PE6
What I am trying to achieve for no reason other than learning and understanding code is this
If after the gosub routine is started no matter what part of the gosub routine I am in and pin C.0 =0 instead of 1 then I wanted pinC.0 go to 0 ,stop the routine and wait on the pinC.1 to go high again
Is this possible with my coding skills or should I go back to watching paint dry
thanks oldvolt


Code:
[color=Black]main:[/color]
[color=Blue]if [/color][color=Purple]pinC.0 [/color][color=DarkCyan]= [/color][color=Navy]1 [/color][color=Blue]then gosub [/color][color=Black]flsh [/color][color=Green]; sub to flsh if pin0 is high[/color]
[color=Blue]goto [/color][color=Black]main [/color][color=Green]; else loop back to start[/color]
[color=Black]flsh: [/color][color=Blue]high B.1 [/color][color=Green]; switch on output B.1[/color]
[color=Blue]pause [/color][color=Navy]5000 [/color][color=Green]; wait 5 seconds[/color]
[color=Blue]low B.1 [/color][color=Green]; switch off output B.1[/color]
[color=Blue]return[/color]
 

inglewoodpete

Senior Member
You could insert a line between "if pinC.0 = 1 then gosub flsh ; sub to flsh if pin0 is high" and "goto main ; else loop back to start"
that does: "Do: Loop Until pinC.0 = 0 ;Wait until button is released"

Leave the pain to dry on its own.
 

oracacle

Senior Member
Code:
[color=Black]main:[/color]
[color=Blue]if [/color][color=Purple]pinC.0 [/color][color=DarkCyan]= [/color][color=Navy]1 [/color][color=Blue]then gosub [/color][color=Black]flsh       [/color][color=Green]; sub to flsh if pin0 is high[/color]
[color=Blue]goto [/color][color=Black]main                           [/color][color=Green]; else loop back to start[/color]

[color=Black]flsh: [/color]
[color=Blue]high B.1                      [/color][color=Green]; switch on output B.1[/color]
[color=Blue]do while [/color][color=Purple]pinC.0 [/color][color=DarkCyan]= [/color][color=Navy]0[/color]

[color=Blue]loop
low b.1                             [/color][color=Green]; switch off output b.1[/color]
[color=Blue]return[/color]
output b.1 will stay high until the c.1 goes high.
 

lbenson

Senior Member
output b.1 will stay high until the c.1 [C.0] goes high.
First you must wait until C.0 goes low, or you will immediately fall through to "low b.1"--so fast you won't have seen the led go on--or maybe it will be going on and off until C.0 goes low as if with PWM with a low duty cycle. It looks like a 5-second "on" period is desired.

IP's solution looks good, depending on exactly what is wanted.
 
Last edited:

oracacle

Senior Member
adding a de-bounce should remove the fall through, providing the pause long enough.
put it in the look, after sending b.1 high, before sending it high, it doesn't matter. It is basically the do loop IP mentioned.
 
Top