Multiple HIGH commands
NB_Nesquik
Posts: 35
Hi,
I know this may sound like a stupid question, but is there a way to have multiple HIGH commands on one line of code?
So instead of having:
HIGH 15
HIGH 14
HIGH 13
HIGH 12
It would all be put on one line. I think I have read somewhere how to do this but I cannot find where I read it at. Thanks for your help.
I know this may sound like a stupid question, but is there a way to have multiple HIGH commands on one line of code?
So instead of having:
HIGH 15
HIGH 14
HIGH 13
HIGH 12
It would all be put on one line. I think I have read somewhere how to do this but I cannot find where I read it at. Thanks for your help.
Comments
OUTS = OUTS & %0000111111111111 ' set pin 12-15 low
or
OUTD = %1111 ' set pin 12-15 high
OUTD = %0000 'set pin 12-15 low
etc
See OUTS, INS, and their brethren OUTA, INA, OUTB, INB, etc. in the Pbasic Manual.
The above presume the pins are already outputs (HIGH makes pin an output as well). If the pins are not outputs, you need a second statement:
OUTD = %1111 ' pin 12-15 will be high if they are outputs
DIRD = %1111 ' make pins 12-15 outputs
Edit: Dang Zoot beat me to it :-)
To set all 16 pins low/high or any combo, use DIRS and OUTS.
OUTS = word value, all 16 pins
OUTL = byte value, pins 0-7
OUTH = byte value, pin 8-15
OUTA = nib value, pins 0-3
OUTB = nib value, pins 4-7
OUTC = nib value, pins 8-11
OUTD = nib value, pins 12-15
OUT0 = pin 0
...
OUT15 = pin 15
' {$STAMP BS2}
' {$PBASIC 2.5}
originaltime VAR Word
newtime VAR Word
number VAR Word
index VAR Word
number_storage DATA 1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768 "Q"
time_storage DATA 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5
OUTS = %0000000000000000
DIRS = %1111111111111111 'set all pins HIGH
DO
GOSUB get_number
GOSUB get_time
OUTS = number
PAUSE newtime
OUTS = OUTS&%0000000000000000 'turn off leds
PAUSE 100
LOOP
get_number:
READ number_storage + index, number
IF (number = "Q") THEN
GOTO finish 'stop program when "Q" is reached
ENDIF
RETURN
get_time:
READ time_storage + index, originaltime
newtime = originaltime * 100 'make time a multiple of a tenth of a second
index = index + 1
RETURN
finish:
DEBUG "Program ended"
END
I dont know what I am missing. Please help. Thanks.
otherwise you will have bytes. Your read also would need to be
number_storage DATA Word 1,2,4,8,16,ect
And
READ number_storage + index, Word number
I think I did it right, or did I?
and
The binary data sequence is ripe to be replaced with ... multiply "number " by 2...
Just a sugestion.
' {$STAMP BS2}
' {$PBASIC 2.5}
originaltime VAR Word
newtime VAR Word
number VAR Word
index VAR Word
number_storage DATA Word 1,10, Word 2,10, Word 4,10, Word 8,10, Word 16,10,
Word 32,10, Word 64,10, Word 128,10, Word 256,10, Word 512,10, Word "Q"
OUTS = %0000000000
DIRS = %1111111111 'set all pins HIGH
DO
GOSUB get_number
GOSUB get_time
OUTS = OUTS&%0000000000 'turn off leds from previous round
OUTS = number
PAUSE newtime
LOOP
get_number:
READ 2 * index + number_storage, Word number
IF (number = "Q") THEN
GOTO finish 'stop program when "Q" is reached
ENDIF
RETURN
get_time:
PAUSE 500
READ number_storage + 3 * index, originaltime
newtime = originaltime * 50 'make time a multiple of a 20th of a second
index = index + 1
RETURN
finish:
OUTS = OUTS&%0000000000 'turn off leds
DEBUG "Program ended"
END
Thanks for all your help.
Then, your read for getting the second "number", or third byte of each pair, should be like below. Remember, the second number of each pair is a byte, and it will be 2 bytes up from the current index:
Aside from not reading the proper byte, your code had "number_storage + 3 * index" which is NOT the same as "3 * index + number_storage". It helps to put parentheses in, sometimes, to make clear the order of operations:
Yours:
Correct:
Personally, I wouldn't have to separate routines for the read, I'd just do it all at once and advance the index by 3: