Shop OBEX P1 Docs P2 Docs Learn Events
running parallel blocks in a sketch — Parallax Forums

running parallel blocks in a sketch

deth502deth502 Posts: 1
edited 2011-11-30 10:15 in BASIC Stamp
completely new to all of this. learning slowly.

heres my question. how can i set the sketch to run 2 different actions at once?

heres what im doing

DO
pattern VAR Byte
counter VAR Byte
other VAR Byte

pattern = 0

IF (IN3 = 1) THEN 'for switch to start

DO

pattern = pattern +1
counter = 0
other = 0
DO

counter = counter +1
HIGH 15
LOW 14
PAUSE 50
LOW 15
PAUSE 100
HIGH 15
PAUSE 50
LOW 15
PAUSE 100
HIGH 15
PAUSE 50
LOW 15
PAUSE 100
HIGH 14
PAUSE 50
LOW 14
PAUSE 100
HIGH 14
PAUSE 50
LOW 14
PAUSE 100
HIGH 14
PAUSE 50
LOW 14
PAUSE 100
LOOP UNTIL counter =6


DO

other = other +1


LOW 14
HIGH 15
PAUSE 500
LOW 15
HIGH 14
PAUSE 500
LOW 14

LOOP UNTIL other = 4

LOOP UNTIL pattern = 2

ENDIF

LOOP


' end lightbar start wigwag

DO
HIGH 10
LOW 11
PAUSE 750
HIGH 11
LOW 10
PAUSE 750

LOOP



now, its for a model police car lights. when i press the button, it makes the main light bar run the strobe pattern 6x, then the flash pattern 4x, and repeats that as many times as you choose for it to run (currently 2x for debugging) and then stop. i have that part working splendidly.

now, AFTER that sequence, i have the short do loop to work the headlight wigwags. problem is, i want that to run concurrently with the light bar, and end when the lightbar sequence ends. i dont know how to code that.

also, all else being equal, does that look like a good sketch ? what im wondering is if its constantly waiting for a button push to start, if it will be consuming battery life when not running. is there something i should add for that? (i mean in the program, not asking about an on/off switch, if i have to resort to the on off switch, ill probably drop the push button and have it go on and off solely off of that.)

tia

Comments

  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2011-11-29 14:26
    Hi, unfortunately everything in a BS2 is sequential, no interupts. Nevertheless it is still a very versatile micro, some things just need a different approach.

    I think the best approach for your project would be to take a look at the PBasic instructions DIRS OUTS and INS (listed under memory and variables in the manual). These instructions allow the simultaneous control of several or all of the I/O pins P0 through P15. By creating a bit pattern for the outputs you can flash the main bar and modify that same bit pattern to include the head lights or not include the head lights.

    If this helps and you need further help post your code here.

    Jeff T.
  • ercoerco Posts: 20,256
    edited 2011-11-30 00:32
    tia:

    Calling it a sketch tends to "give the game away"... :)

    Welcome to the Parallax side, deth502!
  • RiJoRiRiJoRi Posts: 157
    edited 2011-11-30 10:15
    The way I would start solving this problem would be to draw a timing diagram. I'd use graph paper if I had it, or a piece of looseleaf paper turned sideways. Each vertical line would represent 50 time units. Along the left side I would have the different pin names, and the graph itself would show whether the pin was high or low.
    	   __________________________...
    Pin10			 			      |____
       							      ____
    Pin11  __________________________...|
    						    __..........
    Pin14  ______________________|
                  __	   __          __
    Pin15  	 |____|     |____|    |______..........
    
    

    I would then go from left to right, and every time a pin level changed I would write the code (sketch in??) the time delay, and ALL the desired pin levels. For instance, when Pin15 goes from HIGH to LOW, I would write not only that, but the levels for Pins 10,11, and 14.

    HTH,
    --Rich
Sign In or Register to comment.