Programing????
I have a project that will require the BS2 to be able
to tell when the state of a pin
(set up as an Input) has changed from High to Low (Do
Some thing) and from
Low to High (Do Some Thing).
What I would like to do is have anywhere from 4 to 8
inputs to monitor doors in
a remote building I have. If possible, what I would
like to do is monitor the door
with an input and when the door is opened the input to
(lets say) pin0 goes from
High to low, and at this time I want to have the BS2 do
something and only do it once.
And if the door is left open I don't want anything to
happen until the door closes and there will be
a change of pin0 from low to high then I want some
thing to happen and again only do it once
When the door is either left closed or open I don't
want the BS2 to do anything. Again the
only time I want it to do anything is when there is a
transaction between (High to
Low) and (Low to High).
Sorry if I repeated myself to many times...
I have sat and thought about this for many hours and
can't come up with a simply solution,
not even sure this is possible with the BS2....
Thank you,
In Advance
Gene
to tell when the state of a pin
(set up as an Input) has changed from High to Low (Do
Some thing) and from
Low to High (Do Some Thing).
What I would like to do is have anywhere from 4 to 8
inputs to monitor doors in
a remote building I have. If possible, what I would
like to do is monitor the door
with an input and when the door is opened the input to
(lets say) pin0 goes from
High to low, and at this time I want to have the BS2 do
something and only do it once.
And if the door is left open I don't want anything to
happen until the door closes and there will be
a change of pin0 from low to high then I want some
thing to happen and again only do it once
When the door is either left closed or open I don't
want the BS2 to do anything. Again the
only time I want it to do anything is when there is a
transaction between (High to
Low) and (Low to High).
Sorry if I repeated myself to many times...
I have sat and thought about this for many hours and
can't come up with a simply solution,
not even sure this is possible with the BS2....
Thank you,
In Advance
Gene
Comments
thing" will be the same for any door?
ACJacques
Gene Shults wrote:
>
> I have a project that will require the BS2 to be able
> to tell when the state of a pin
> (set up as an Input) has changed from High to Low (Do
> Some thing) and from
> Low to High (Do Some Thing).
>
> What I would like to do is have anywhere from 4 to 8
> inputs to monitor doors in
> a remote building I have. If possible, what I would
> like to do is monitor the door
> with an input and when the door is opened the input to
> (lets say) pin0 goes from
> High to low, and at this time I want to have the BS2 do
> something and only do it once.
> And if the door is left open I don't want anything to
> happen until the door closes and there will be
> a change of pin0 from low to high then I want some
> thing to happen and again only do it once
> When the door is either left closed or open I don't
> want the BS2 to do anything. Again the
> only time I want it to do anything is when there is a
> transaction between (High to
> Low) and (Low to High).
>
> Sorry if I repeated myself to many times...
> I have sat and thought about this for many hours and
> can't come up with a simply solution,
> not even sure this is possible with the BS2....
>
> Thank you,
> In Advance
> Gene
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
different inputs.
Some may be the same.
Original Message
From: "AC Jacques" <acjacques@i...>
To: <basicstamps@yahoogroups.com>
Sent: Wednesday, February 28, 2001 8:06 PM
Subject: Re: [noparse][[/noparse]basicstamps] Programing????
> Do you need do different things depending of the
door, or the "do some
> thing" will be the same for any door?
> ACJacques
>
> Gene Shults wrote:
> >
> > I have a project that will require the BS2 to be
able
> > to tell when the state of a pin
> > (set up as an Input) has changed from High to Low
(Do
> > Some thing) and from
> > Low to High (Do Some Thing).
> >
> > What I would like to do is have anywhere from 4 to
8
> > inputs to monitor doors in
> > a remote building I have. If possible, what I would
> > like to do is monitor the door
> > with an input and when the door is opened the input
to
> > (lets say) pin0 goes from
> > High to low, and at this time I want to have the
BS2 do
> > something and only do it once.
> > And if the door is left open I don't want anything
to
> > happen until the door closes and there will be
> > a change of pin0 from low to high then I want some
> > thing to happen and again only do it once
> > When the door is either left closed or open I don't
> > want the BS2 to do anything. Again the
> > only time I want it to do anything is when there is
a
> > transaction between (High to
> > Low) and (Low to High).
> >
> > Sorry if I repeated myself to many times...
> > I have sat and thought about this for many hours
and
> > can't come up with a simply solution,
> > not even sure this is possible with the BS2....
> >
> > Thank you,
> > In Advance
> > Gene
> >
> >
> >
> > Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/
>
>
>
> Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/
>
>
>to tell when the state of a pin
>(set up as an Input) has changed from High to Low (Do
>Some thing) and from
>Low to High (Do Some Thing).
>
>What I would like to do is have anywhere from 4 to 8
>inputs to monitor doors in
Transistions can be detected by using XOR logic between the old state
of the pin and the new state. Here's a snippet:
' door inputs to P0 to P8
x0 var byte ' old state of doors
x1 var byte ' new state of doors
xx var byte ' transition state of doors
xy var byte ' transitiion state 0->1
ix var nib ' counter to scan through doors
x0=inL ' read states at start
waiting:
x1=inL ' read new state
xx=x1 ^ x0 ' see if there are any transitions
x0=x1 ' update old state
branch xx,[noparse][[/noparse]waitng] ' waiting until something happens
' come here when something happens
xy = xx & x1 ' distinguish 0->1 xitions from 1->0
for ix=0 to 7 ' now see which doors did it
branch ix+1*xx.bit0(ix),[noparse][[/noparse]loopnext,firstdoor,seconddoor,...,seventhdoor]
loopnext:
next
goto waiting ' tested all the doors
firstdoor:
branch xy.bit0,[noparse][[/noparse]door1opened,door1closed]
door1opened:
' do something
goto loopnext ' back to test other doors
door1closed:
' do something
goto loopnext
seconddoor:
branch xy.bit1,[noparse][[/noparse]door2opened,door2closed]
door2opened:
' do something
goto loopnext ' back to test other doors
' etc etc
If you could be sure that only one door will never change at a time,
the bit scanning would not be necessary and the main branch could go
directly to the door actions:
waiting:
x1=inL ' read new state
xx=x1 ^ x0 ' see if there are any transitions
xy = xx & x1 ' distinguish 0->1 xitions from 1->0
x0=x1 ' update old state
branch ncd xx,[noparse][[/noparse]waiting,firstdoor,seconddoor,..,seventhdoor]
The NCD operator returns the index of the highest bit set in a binary
value, for example xx=%00010000 would return 5 (transition on fifth
door). A value xx=%00000000 means that nothing has happened and the
branch just goes right back to waiting.
The same thing can be done using a lot of if-then logic, instead of
XOR logic, but it tends to turn into a big tangled bowl of linguini!
good luck!
-- Tracy Allen
electronically monitored ecosystems
http://www,emesystems.com
oldstate var byte
newstate var byte
changed var byte
start:
oldstate= INL ('pins 0-7) 'your doors sensors
loop:
newstate = INL
if newstate = oldstate then loop: 'remain looping if not change
changed = oldstate ^ newstate 'XOR will "1" only changed pins"
debug home
debug bin8 changed, cr 'debug will show door changed as "1"
if changed.bit0= 1 then dosomething0
if changed.bit1= 1 then dosomething1
...... 'same for other doors
dosomething0:
'do here for pin 0
goto start ' start again
dosomething1:
'do here for pin 1
goto start ' start again
...... 'same for other doors
Remember that since Stamp cannot do multitask it will not detect a
further change when it is doing "something". If the task could be done
in a short time this will not be a problem for you. Another drawback is
if two or more doors change at the same time.For this a solution could
be another approach after the the XOR.
Regards;
ACJacques
Gene Shults wrote:
>
> The (Do Something) will probably be different for
> different inputs.
> Some may be the same.
>
>
Original Message
> From: "AC Jacques" <acjacques@i...>
> To: <basicstamps@yahoogroups.com>
> Sent: Wednesday, February 28, 2001 8:06 PM
> Subject: Re: [noparse][[/noparse]basicstamps] Programing????
>
> > Do you need do different things depending of the
> door, or the "do some
> > thing" will be the same for any door?
> > ACJacques
> >
> > Gene Shults wrote:
> > >
> > > I have a project that will require the BS2 to be
> able
> > > to tell when the state of a pin
> > > (set up as an Input) has changed from High to Low
> (Do
> > > Some thing) and from
> > > Low to High (Do Some Thing).
> > >
> > > What I would like to do is have anywhere from 4 to
> 8
> > > inputs to monitor doors in
> > > a remote building I have. If possible, what I would
> > > like to do is monitor the door
> > > with an input and when the door is opened the input
> to
> > > (lets say) pin0 goes from
> > > High to low, and at this time I want to have the
> BS2 do
> > > something and only do it once.
> > > And if the door is left open I don't want anything
> to
> > > happen until the door closes and there will be
> > > a change of pin0 from low to high then I want some
> > > thing to happen and again only do it once
> > > When the door is either left closed or open I don't
> > > want the BS2 to do anything. Again the
> > > only time I want it to do anything is when there is
> a
> > > transaction between (High to
> > > Low) and (Low to High).
> > >
> > > Sorry if I repeated myself to many times...
> > > I have sat and thought about this for many hours
> and
> > > can't come up with a simply solution,
> > > not even sure this is possible with the BS2....
> > >
> > > Thank you,
> > > In Advance
> > > Gene
> > >
> > >
> > >
> > > Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/
> >
> >
> >
> > Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/
> >
> >
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
> >to tell when the state of a pin
> >(set up as an Input) has changed from High to Low (Do
> >Some thing) and from
> >Low to High (Do Some Thing).
> >
> >What I would like to do is have anywhere from 4 to 8
> >inputs to monitor doors in
>a remote building I have. If possible, what I would
>like to do is monitor the door
>with an input and when the door is opened the input to
>(lets say) pin0 goes from
>High to low, and at this time I want to have the BS2 do
>something and only do it once.
..
>The (Do Something) will probably be different for
>different inputs.
>Some may be the same.
Hi Gene,
Here is an alternative program for checking all the doors, that runs
faster by using the NCD operator for all the branching. This one can
handle events where two or more doors happen to change at the the
same time.
' door inputs to P0 to P8
x0 var byte ' old state of doors
x1 var byte ' new state of doors
xx var byte ' transition state of doors
xy var byte ' transitiion state 0->1
x0=inL ' read states at start
waiting:
x1=inL ' read new state
xx=x1 ^ x0 ' see if there are any transitions
xy = xx & x1 ' distinguish 0->1 xitions from 1->0
x0=x1 ' update old state
checkalldoors:
branch ncd xx,[noparse][[/noparse]waiting,firstdoor,seconddoor,..,eigthdoor]
firstdoor:
xx=xx & %11111110 ' knock down the 1st door bit
branch xy.bit0,[noparse][[/noparse]door1opened,door1closed]
door1opened:
' do something
goto checkalldoors ' back to test other doors
door1closed:
' do something
goto checkalldoors
seconddoor:
xx=xx & %11111101 ' knock down the 2nd door bit
branch xy.bit1,[noparse][[/noparse]door2opened,door2closed]
door2opened:
' do something
goto checkalldoors ' back to test other doors
door2closed:
' do something
goto checkalldoors
' etc etc
Suppose two doors change at the same time, for example, xx=%00010100.
The NCD operator returns the index of the highest bit set in a binary
value, so NCD %00010100 would return 5 (transition on fifth
door). That would make the routine branch to the fifthdoor routine,
which now knocsk down the fifth bit, making xx=%00000100. After
doing something for the fifth door, the program returns to the
checkalldoors point, where now NCD %00000100 makes the program branch
to the thriddoor routine, which knocks down the third bit and does
the action for the third door and again returns to checkalldoors.
Now xx=0, and NCD 0 is zero so the routine returns to waiting for the
next event.
-- Tracy Allen
electronically monitored ecosystems
http://www,emesystems.com
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
Tracy Allen
electronically monitored ecosystems
http://www,emesystems.com
And
AC Jacques
For the leads on the programing I was having problem
with.
This was exactly what I was looking for..
Two very sharp Guys..
Thanks Again
Gene
>not even sure this is possible with the BS2....
Hi Gene,
When you say inflammatory things like that, it is sure to be challenge!
best regards,
-- Tracy