my CASE expression needs a fix
karli
Posts: 16
···· all is well up to·· Calling the PUB decode code:
······· if·ina[noparse][[/noparse]21] == 1·············· 'if my P21 push button has been pressed
·········· if ina[noparse][[/noparse]9] == 0·············· AND if my 2sec P9 Led gate initiated by a cog has timed out
············· outa[noparse][[/noparse]6..4]++··········· then I increment the bits in [noparse][[/noparse]6..4]
······· if ina[noparse][[/noparse]9] == 0···························· if [noparse][[/noparse]9] Led is still off· = P9 =·LOW
·········· waitcnt(clkfreq/100 + cnt)········ 10msec delay
·········· decode································· issue Call to· PUB decode
·········· launch·································· issue Call to· Pub Launch····· 'Main
·PUB· decode
······· CASE·· ina[noparse][[/noparse]6..4]········ I want to test for the binary pattern of the [noparse][[/noparse]6..4] bits
··········· 001:····· !outa[noparse][[/noparse]4]····· turn on the P4 led
··········· 010:····· !outa[noparse][[/noparse]5]····················· P5
··········· 011:······!outa[noparse][[/noparse]6]····················· P6
··········· 100:····· !outa[noparse][[/noparse]7]····················· P7
············101:····· !outa[noparse][[/noparse]8]······················P8
··········· OTHER:···· ???············· what code do I use to clear all bits in [noparse][[/noparse]6..4]·· ?
············································ and return to the decode Call and then call launch ?
············································ the·CASE decoding doesn't work but it returns to call
············································ launch ok and I can start a new P21 button press
············································ sequence.
·· Thanks for any insight,
···· karli
·
······· if·ina[noparse][[/noparse]21] == 1·············· 'if my P21 push button has been pressed
·········· if ina[noparse][[/noparse]9] == 0·············· AND if my 2sec P9 Led gate initiated by a cog has timed out
············· outa[noparse][[/noparse]6..4]++··········· then I increment the bits in [noparse][[/noparse]6..4]
······· if ina[noparse][[/noparse]9] == 0···························· if [noparse][[/noparse]9] Led is still off· = P9 =·LOW
·········· waitcnt(clkfreq/100 + cnt)········ 10msec delay
·········· decode································· issue Call to· PUB decode
·········· launch·································· issue Call to· Pub Launch····· 'Main
·PUB· decode
······· CASE·· ina[noparse][[/noparse]6..4]········ I want to test for the binary pattern of the [noparse][[/noparse]6..4] bits
··········· 001:····· !outa[noparse][[/noparse]4]····· turn on the P4 led
··········· 010:····· !outa[noparse][[/noparse]5]····················· P5
··········· 011:······!outa[noparse][[/noparse]6]····················· P6
··········· 100:····· !outa[noparse][[/noparse]7]····················· P7
············101:····· !outa[noparse][[/noparse]8]······················P8
··········· OTHER:···· ???············· what code do I use to clear all bits in [noparse][[/noparse]6..4]·· ?
············································ and return to the decode Call and then call launch ?
············································ the·CASE decoding doesn't work but it returns to call
············································ launch ok and I can start a new P21 button press
············································ sequence.
·· Thanks for any insight,
···· karli
·
Comments
1) ina[noparse][[/noparse] 6..4 ] gets the value of the I/O pins.· Depending on how you've hooked them up and what you've done to set the dira register, that may or may not be the same as the outa register bits.· 1xx is pin 6 and xx1 is pin 4 the way you've written it.· I don't know if that's what you wanted.
2) !outa[noparse][[/noparse] x ] toggles the specified outa bit.· Again, that may or may not be what you actually want.
3) To set bits 6..4 of outa to zero, you can just do: outa[noparse][[/noparse] 6..4 ] := 0
4) All methods (subroutines) have an implicit return as the last statement
5) The notation for binary values is %000, %001, %010, %011, %100, %101, %110, %111.· What you wrote was decimal (1, 10 (ten), 11 (eleven), 100 (one hundred), 101 (one hundred and one).
Thanks for coming back me.
let me start at the beginning: I'm using P21 as button entry and P4...P9 as LED outputs in the
standard PE lab configuration.
I want to Mux(multiplex) the function of only one push button into 5 possible output states, in this case,
P4..P8; P4 is LED#1 for state #1 and P8 is LED#5 for state#5
P9 comes on when I first push P21 for 2 sec via a newcog operation
from the moment P9 comes on I have 2 sec to hit P21 button up to 5 times
when P9 turns off signalling the end of that 2sec gate; so, if I push P21 6 times, the first press is to start
the P9 gate and that leaves a count of 5 for outa[noparse][[/noparse]6..4]; i.e., P6 and P4 LEDs are lit
all this works to this point.
now for decode: I want to translate the binary pattern in bits 6 5 4 in [noparse][[/noparse]6..4] into a single LED
output; i.e., a binary 5 should turn on P8, which is output state#5 and P4 and P6 should extinguish.
when I push P21 while P9 gate is active for 2sec I'm currently toggling the P4 P5 or P6 LEDs, but in my
final version I would run this count process 'dark" with only P9 being lit while I do
the P21 presses. and after P9 goes off then the state result should be displayed.
In my CASE example I mistakenly skipped the % to show that the outa[noparse][[/noparse]6..4] values was supposed to be
treated as a binary. I also copied the bitwise NOT ! from the Propeller Manual, not realizing that
it was meant to invert my outputs in the decode routine.
of course attention to detail is the ahllmark of programming !
I hope I was clearer this time as to what I had in mind.
In order to do my P21 toggling "in the dark" without P4 5 6 Leds turning on what other technique
can I use ? instead of using outa[noparse][[/noparse]6..4]++ whenever I push P21 ?
your help is much appreciated,
karli
that's quite simple
as a quick answer to your question:
use a variable instead of the output-register outa
i would prefer ALWAYS using variables for MANIPULATING things
like increment/decrement values or compare values.
This would be done by copying the state of the ina- or outa-register to a variable
do all the manipulation with the variable and finally write the FINALLY result to the
ina/outa-register again.
To show some more programming-techniques a modified version of your code:
best regards
Stefan
·· I'm immensely grateful for your detailed reply to my
·· CASE Expression query on 10July08; I printed out your
·· Spin code and will study it intently and try it out on my
·· Prop Lab setup. I'll send a post when I start hollering
·· "Eureka"· and wake up the neighborhood (hi)
··· most sincerely yours,
··· karli