using START

69-cat

Member
I try to work out my own problems by trial and error but this time I asking the experts! Can I control the "Start" command by using an input. I am using a PIR to trigger my Halloween props but wanted to setup a code to trigger a string of strobe with different timing values using a single chip. The only other simple option that I can come up with is to use a 08m2 to handle the input and power up the 14m2 to work the strobes.
Dave
View attachment multi strobe trigger test.bas
 

hippy

Technical Support
Staff member
You can use SUSPEND, RESUME and RESTART commands to control the execution of tasks, and you can have the START0 task control the others. If I understand what you want to do - run the four strobes for 30 seconds after activation then stop until next activation - then this would probably be a way to do that, though untested ...

Code:
#Picaxe 14m2
symbol PIR = pinc.3
symbol strobe1 = B.1
symbol strobe2 = B.2
symbol strobe3 = B.3
symbol strobe4 = B.4

pause 45000			'time for the PIR to settle 
main:
if PIR=0 then main

resume 1
resume 2
resume 3
resume 4

Pause 30000

restart 1
restart 2
restart 3
restart 4

goto main

start1:
  low strobe1
  suspend 1
  do
    high strobe1 : pause 25
    low  strobe1 : pause 65
  loop

start2:
  low strobe2
  suspend 2
  do
    high strobe2 : pause 30
    low  strobe2 : pause 55
  loop

start3:
  low strobe3
  suspend 3
  do
    high strobe3 : pause 25
    low  strobe3 : pause 60
  loop

start4:
  low strobe4
  suspend 4
  do
    high strobe4 : pause 30
    low  strobe4 : pause 50
  loop
 

69-cat

Member
Hippy, even though you stated untested, it works just like I wanted it to! I now have NEW commands that I can play with..
Thanks Again:cool:
Dave
 

hippy

Technical Support
Staff member
Glad it worked.

There is another approach to using SUSPEND, RESUME and RESTART, and that is to have the tasks just loop until some status flag is set, in this case when 'b0' is non-zero the tasks do their thing then idly loop when 'b0' is zero again.

Code:
#Picaxe 14m2
symbol PIR = pinc.3
symbol strobe1 = B.1
symbol strobe2 = B.2
symbol strobe3 = B.3
symbol strobe4 = B.4

pause 45000			'time for the PIR to settle 

main:
if PIR=0 then main

[b]b0 = 1[/b]

Pause 30000

[b]b0 = 0[/b]

goto main

start1:
  do
    [b]do : loop while b0 = 0[/b]
    high strobe1 : pause 25
    low  strobe1 : pause 65
  loop

start2:
  do
    do : loop while b0 = 0
    high strobe2 : pause 30
    low  strobe2 : pause 55
  loop

start3:
  do
    do : loop while b0 = 0
    high strobe3 : pause 25
    low  strobe3 : pause 60
  loop

start4:
  do
    do : loop while b0 = 0
    high strobe4 : pause 30
    low  strobe4 : pause 50
  loop
This isn't quite so efficient as the fist version so I would stick with that as it works, but this 'using a flag' trick can be useful in some cases as one only needs to control the flags, rather than use any SUSPEND, RESUME and RESTART. It uses less memory and isn't quite so complicated.
 
Top