running parallel blocks in a sketch
deth502
Posts: 1
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
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
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.
Calling it a sketch tends to "give the game away"...
Welcome to the Parallax side, deth502!
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