inA and for next
Hi Folks,
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
[noparse][[/noparse]Non-text portions of this message have been removed]
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
[noparse][[/noparse]Non-text portions of this message have been removed]
Comments
It would help for us to know what goes in the "then" part of your
statement. Is this a case where you want to debounce the inputs
and/or trigger the associated action only once when the input changes
state? What should happen when two or more are pressed at the same
time?
Here is an idea using the esoteric NCD, DCD and BRANCH commands:
X var word
Y var nib
loopback:
X =ins & $0FFF ' get the 12 inputs
Y = NCD X ' encode, as a number from 0 to 12
' zero means none are pressed.
if Y=0 then loopback
Y=Y-1 ' 12 inputs, 0 to 11
error= DCD Y - X max 1 ' :=1 if two or more inputs
if error then loopback
branch Y,[noparse][[/noparse]action1, ... , action12] ' do stuff
'...
-- 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
Original Message
From: ulibasic <ulibasic@r...>
To: <basicstamps@yahoogroups.com>
Sent: Wednesday, July 31, 2002 1:39 PM
Subject: [noparse][[/noparse]basicstamps] inA and for next
> Hi Folks,
>
> 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
>
>
> [noparse][[/noparse]Non-text portions of this message have been removed]
>
>
> 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/
>
HI, Uli
A good solution comes from combination of LOOKDOWN ... and BRANCH....
statement.
Try this:
'{$STAMP BS2}
DIRS = %1110000000000000 'pin 0 ...7 for input
'others for output,if you
want
PortVal var word
'======= MAIN ==================================================
AGAIN: PortVal = 4095
lookdown INS,[noparse][[/noparse]1,2,4,8,16,32,64,128,256,512,1024,2048],PortVal
branch PortVal,[noparse][[/noparse]EV0,EV1,EV2,EV3,EV4,EV5,EV6,EV7,EV8,EV9,EV10,EV11]
DEBUG "no pin called",cr 'any actions you want
PAUSE 200 'any actions you want
goto AGAIN
'======= events alligned to pin 0...11, ===================================
EV0: DEBUG "was pin 00",cr 'any actions you want
goto AGAIN
EV1: DEBUG "was pin 01",cr 'any actions you want
goto AGAIN
EV2: DEBUG "was pin 02",cr 'any actions you want
goto AGAIN
EV3: DEBUG "was pin 03",cr 'any actions you want
goto AGAIN
EV4: DEBUG "was pin 04",cr 'any actions you want
goto AGAIN
EV5: DEBUG "was pin 05",cr 'any actions you want
goto AGAIN
EV6: DEBUG "was pin 06",cr 'any actions you want
goto AGAIN
EV7: DEBUG "was pin 07",cr 'any actions you want
goto AGAIN
EV8: DEBUG "was pin 08",cr 'any actions you want
goto AGAIN
EV9: DEBUG "was pin 09",cr 'any actions you want
goto AGAIN
EV10: DEBUG "was pin 10",cr 'any actions you want
goto AGAIN
EV11: DEBUG "was pin 11",cr 'any actions you want
goto AGAIN
Successfull recognicing a single key on pin 0... .11, pull up the pin.
If you want to recognice a combination of HIGH-setted pins, it is easy. Enhance
the
LOKDOWN table with the alligned decimal values. For example: PortVal 14 will
recognice keyed pin1 & pin2 & pin3 ( makes 2+4+8).
Klaus Zahnert