OUT command question
I'm playing with the BS2....
The following code doesn't work, but I hope it's pretty apparent what I want to do. How else can I do this?
The "1" can actually be different values read from an array.
The following code doesn't work, but I hope it's pretty apparent what I want to do. How else can I do this?
x VAR Byte FOR x=7 TO 4 OUTx = 1 NEXT
The "1" can actually be different values read from an array.

Comments
FOR x=7 TO 4
OUT &h100+x, 1
NEXT X
but in PBASIC I can't find a way to do that just yet.
Actually that was a bad example, but hopefully you still understand the question
FOR x = 7 to 4 OUT0(x) = 1 PAUSE 1000 NEXTOUT0(7) is the same as OUT7 etc.
Thank you! That's brilliant... I spent a lot of time in the manual last night and didn't see this!
If I could find a previous email thread, I'd copy the information related from Mr. Allen on how the I/O bits are treated like an array (maybe he'll read this and comment again).
Regards,
DJ
http://forums.parallax.com/showthread.php?122525-INx-Question&highlight=array+OUT%28
DJ
(The program wont run as is... the data must be loaded into an array first!)
'Layout the array as follows: Keyp 1,2,3,F, 4,5,6,E, 7,8,9,D, A,0,B,C x VAR nib y VAR nib Kloop: FOR x=0 TO 3 OUT0(x)=1 FOR y=4 TO 7 IF IN0(y)=1 DEBUG Keyp(X*4 +Y -4) NEXT OUT0(x)=0 NEXT GOTO KloopIt's a 16 button keypad read routine, which if I have it figured right will report simultaneous button presses. SWEET
I'm trying to make a BigTrak..... just like we used to have as kids.
DIRA = %1111
That before the OUTx commands to those pins will be effective.
Another way to set one row at a time high uses OUTA for pins p0 to p3, and the DCD operator.
DIRA = $f DO FOR x=0 TO 3 OUTA = DCD x ' set one row at a time to high level, p0 to p3 DEBUG CR, bin4 INB ' read bits on p4 to p7 NEXT PAUSE 1000 LOOPIF (INB AND 1) = 1 THEN DEBUG "Button 1 pressed"
......
IF (INB AND 8) = 1 THEN DEBUG "Button F pressed"
I plan to store the operator entered steps in an array, with the first token as a direction, followed by a time from 0-9. I hope to store eight steps, which should be 8*2 nibbles or 16 bytes. Anyways, I suppose that's outside the reason for this post.
Thanks to all for the help!
SELECT INB CASE $0001 DEBUG "Button 1 Pressed" CASE $0010 DEBUG "Button 2 Pressed" . . . CASE $1000 DEBUG "Button 8 Pressed" ENDSELECTI hope the syntax is correct (pulling if from memory after having a HUGE lunch! zzZZZZzzzzZZ)
x VAR Nib keys VAR Word keyA VAR keys.nib0 key0 VAR keys.bit0 DIRA = $f DO GOSUB keyScan DEBUG CR, IBIN16 keys IF keys THEN GOSUB keyDecode PAUSE 256 LOOP keyScan: FOR x=0 TO 3 OUTA = DCD x ' set one row at a time to high level, p0 to p3 keyA(x) = INB ' read bits on p4 to p7, keys as an array of nibs NEXT RETURN keyDecode: DEBUG CR, "The keys pressed are: " FOR x=0 TO 15 IF key0(x) THEN ' read individual bits of word keys as array DEBUG DEC x, " " NEXT RETURNI dunno how to display a hex number, so key "A" shows as 10, "B" as 11 and so on.
I could easily call this routine on demand. I'd probably check periodically for a keypress by bringing all the outputs high, and look for a non-zero on INA, then call this routine if needed.
' {$STAMP BS2px} ' {$PBASIC 2.5} 'Layout the array as follows: (Note that $A will print as 10, $B as 11, etc) Kyval DATA 1,2,3,$F DATA 4,5,6,$E DATA 7,8,9,$D DATA $A,0,$B,$C keyp VAR Nib(16) ptr VAR Word x VAR Nib y VAR Nib 'I can use the DIR command once I settle on a circuit OUTPUT 7 OUTPUT 6 OUTPUT 5 OUTPUT 4 INPUT 3 INPUT 2 INPUT 1 INPUT 0 'Load Key value data into keyp array FOR x=0 TO 15 READ ptr,keyp(x) ptr=ptr+1 DEBUG DEC keyp(x)," " NEXT DEBUG CR, "Array loaded",CR PAUSE 2000 'Do nothing but hold the message GetKeyVals: FOR y=0 TO 3 'Cycle through output lines P4 - P7 OUT0(y+4)=1 'Pull the line high FOR x=0 TO 3 'Cycle through the input lines IF IN0(x)=1 THEN DEBUG DEC keyp(y*4 +x) 'Test current input line for high, blit key NEXT 'Next input line OUT0(y+4)=0 'Close output line NEXT 'Next output line PAUSE 250 'A little key debounce GOTO GetKeyVals 'or RETURNYou can find it here: http://www.parallax.com/tabid/440/Default.aspx
DJ
I'm just happy to be able to help.
DJ