Shop OBEX P1 Docs P2 Docs Learn Events
AW: [basicstamps] inA and for next — Parallax Forums

AW: [basicstamps] inA and for next

ArchiverArchiver Posts: 46,084
edited 2002-08-01 18:22 in General Discussion
Hey Tracy,

yes, esoteric is the word...


I must admit that I donot understand one single line of your code which
might partly change after I will have read the related pages of stampworks.

What I want to do is branch to different actions depending on which button
is pressed including actions that are triggered when two certain buttons are
pressed. That means if three is pressed, the program should check if five is
pressed too. So best would be a routine that tells me something like "good
morning uli, at the moment buttons two and seven are pressed, have a nice
day"

Do you think you could give me two or three more words on your code? I
marked the parts that I understand the least...

Thanks very much Tracy!

Have a nice day, Uli


Here is an idea using the esoteric NCD, DCD and BRANCH commands:

X var word 'OK
Y var nib 'OK too
loopback:
X =ins & $0FFF ' get the 12 inputs '$=FFF makes it 12 bit, right?
Y = NCD X ' encode, as a number from 0 to 12 'dont understand
' zero means none are pressed. OK!
if Y=0 then loopback
Y=Y-1 ' 12 inputs, 0 to 11 Yes, OK
error= DCD Y - X max 1 ' :=1 if two or more inputs Who is Max? :-)
if error then loopback
branch Y,[noparse][[/noparse]action1, ... , action12] ' do stuff OK
'...

Just to give you the idea:
Actually it is not about buttons, what I am building is a Hypnotic puppet,
that has eicht integrated Qprox-sensors and a quadravox chip. It is lying on
a table and over headphones it tells you to touch it ("please touch my left
hand") then it guides you over its body, always telling you what to do. It
can even 'feel' your hands before you touch it and it complains when you
touch the wrong part of body. Very interesting experience for the user, very
very interesting sculpture to look at from the outside: concentrated people
wearing headphones and doing very strange things to a puppet...

-- best regards
Tracy Allen
electronically monitored ecosystems
http://www.emesystems.com
mailto:tracy@e...



>I have a (simple?) programming question: I want to read 12 stamp inputs and
>trigger an action (soundfile on a quadravox) depending on which input is
>high. Important: if more than one input is high I need to know that too. I
>can solve the problem, for example by writing:
> if in1=1 then...
> if in2=1 then...
>But I cannot find any elegant way, like any kind of loop.
>Any ideas?
>Thanks for help, Uli

To UNSUBSCRIBE, just send mail to:
basicstamps-unsubscribe@yahoogroups.com
from the same email address that you subscribed. Text in the Subject and
Body of the message will be ignored.


Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/




[noparse][[/noparse]Non-text portions of this message have been removed]

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2002-08-01 18:22
    Hi Uli,

    >What I want to do is branch to different actions depending on which button
    >is pressed including actions that are triggered when two certain buttons are
    >pressed. That means if three is pressed, the program should check if five is
    >pressed too. So best would be a routine that tells me something like "good
    >morning uli, at the moment buttons two and seven are pressed, have a nice
    >day"


    >...what I am building is a Hypnotic puppet,
    >that has eicht integrated Qprox-sensors and a quadravox chip. It is lying on
    >a table and over headphones it tells you to touch it ("please touch my left
    >hand")...


    Wow, scary, doctor! The problem is, there are so many possibilities.
    If you need to consider every possible combination of 12 buttons,
    there are 2^12=4096 possibilities. Even with every combination of
    just 1 or 2 buttons, that would come to 72 possibilities (if I have
    figured right). Is there some system to the responses when two or
    more parts are touched at once? ("why are you touching both my
    'aaaaa' and my 'bbbbb' at the same time?". That could be done with
    relatively short, systematic code, where you combine relatively few
    canned phrases. Or, are the responses unique and ad hoc for each
    combination? In that case you will probably need a big lookup table
    in BS2p or external eeprom.


    >Do you think you could give me two or three more words on your code? I
    >marked the parts that I understand the least...
    >
    >Here is an idea using the esoteric NCD, DCD and BRANCH commands:
    >
    > X var word 'OK
    > Y var nib 'OK too
    > loopback:
    > X =ins & $0FFF ' get the 12 inputs '$=FFF makes it 12 bit, right?

    Right, $0fff is a "mask" that makes sure the top four bits of the
    result, X, are zeros. X is still a word, with 16 bits. I want 12 of
    those bits to correspond to the current state on input pins p0 to
    p11, but I do not want to include the state of pins p12 to p15 (which
    may be doing something unrelated in the program). The "&" symbol is
    logical AND, that combines the 16 bits of INS with the 16 bits of
    $0fff. In binary, $0fff=%0000111111111111. A bit in X will be set=1
    only if the corresponding bits in _both_ INS and the mask are set=1.


    > Y = NCD X ' encode, as a number from 0 to 12 'dont understand
    > ' zero means none are pressed. OK!

    Look in the Stamp manual under the math operators. NCD is short for
    "encode". It gives the position of the most significant bit in the
    variable X. For example, if X=%0000000001001000, then NCD X = 7,
    because bit number 7 is the highest one set. Another example, if
    X=%1000010010001011, then NCD X = 16, because the 16th bit is the
    highest one. Careful, note that NCD starts numbering at 1, not zero.
    A result of zero means no bits are set.

    > if Y=0 then loopback
    > Y=Y-1 ' 12 inputs, 0 to 11 Yes, OK
    > error= DCD Y - X max 1 ' :=1 if two or more inputs Who is Max? :-)

    MAX and DCD are also defined in the Stamp manual in the section on
    math operators. DCD means "decode". It is kind of the opposite of
    NCD, in that it sets the corresponding bit in the 16-bit number. It
    takes a number from 0 to 15 and gives back a number 1, 2, 4, 8, ...
    32768. Example: if Y=6, then DCD Y = %0000000001000000. Or, if
    Y=15, then DCD Y = %1000000000000000. Careful, DCD starts numbering
    the bits at zero.

    Now if only one of your buttons is pressed, then only one bit will be
    set in INS, and when you follow it through, you find that DCD Y will
    be the same as X, the same one and only bit set. However, if more
    than one bit is set in INS, there will still only be one bit set in
    DCD Y, and the quantity DCD Y - X will be some value greater than
    zero. This is where MAX comes in. MAX 1 limits the value of "error"
    to be either 0 or 1. That is, a MAXimum of 1.

    Does that help, or just confuse the issue?!

    It might not really help with your problem, because having two
    pressed at the same time is not really an error in what you are
    doing. But what are you going to do when more than two parts are
    touched at once?

    > if error then loopback
    > branch Y,[noparse][[/noparse]action1, ... , action12] ' do stuff OK
    > '...
    >


    -- best regards
    Tracy Allen
    electronically monitored ecosystems
    http://www.emesystems.com
    mailto:tracy@e...
Sign In or Register to comment.