Newbie Alert !!!!
Archiver
Posts: 46,084
I am trying to understand this but it makes no sense to me at all.So
if you got some crayons can you draw me a picture I can
understand.Here is the first part:
switch=INC & 7 ' only 3 switches
switch=switch ^ 7 ' reverse sense (active low->active high)
Here is the second part:
IF INC <> 15 THEN readloop
I guess my big question is what value do you apply to the pins
covered by INC.
Thanks,
Stan
if you got some crayons can you draw me a picture I can
understand.Here is the first part:
switch=INC & 7 ' only 3 switches
switch=switch ^ 7 ' reverse sense (active low->active high)
Here is the second part:
IF INC <> 15 THEN readloop
I guess my big question is what value do you apply to the pins
covered by INC.
Thanks,
Stan
Comments
appears to be doing is reading that group, extracting three of the pins
for the variable switch, then retesting the group and continuing at the
label "readloop" if all inputs on INC are high.
The inputs to the BASIC Stamp micro are digital: 0 (ground) and 1 (+5v).
The code indicates active-low inputs. That means the inputs are
pulled-up to Vdd (+5) through resistors (probably 10K) and a button
connects between each of the pins and ground. When a button is open,
the pin will see "1" (+5v), when the button is pressed the input will se
"0" (ground).
This is standard digital stuff. Since you've identified yourself as
new, let me suggest you download our "What's A Microcontroller?" text
from our web site.
-- Jon Williams
-- Applications Engineer, Parallax
-- Dallas Office
Original Message
From: kingtweeter [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=x3vFJlc3l2qoesF1SSnrsAuTp5aUH-BsDpU9iImHojILea30Bmmv-QW7Chi0eJYkHCPI5IxNb9ij2rIsPAU]jamachine@c...[/url
Sent: Wednesday, March 31, 2004 6:51 AM
To: basicstamps@yahoogroups.com
Subject: [noparse][[/noparse]basicstamps] Newbie Alert !!!!
I am trying to understand this but it makes no sense to me at all.So
if you got some crayons can you draw me a picture I can
understand.Here is the first part:
switch=INC & 7 ' only 3 switches
switch=switch ^ 7 ' reverse sense (active low->active high)
Here is the second part:
IF INC <> 15 THEN readloop
I guess my big question is what value do you apply to the pins
covered by INC.
Thanks,
Stan
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.
Yahoo! Groups Links
This message has been scanned by WebShield. Please report SPAM to
abuse@p....
And I will read that I am also going to post all of the code this
time,because part of this still makes no sense[noparse]:([/noparse]IF INC <> 15 THEN
readloop)the code length is 5 so you have 5 key presses if pin 8
=1,pin9=2,pin10 =3,and if the code is 3,3,1,2,3 and it is looking
for 15 that is my problem.
Thans,
Stan
'{$STAMP BS2}
' Combo lock demo by Al Williams
' Shows how to use an RC network for generating
' a timeout
rctrig CON 7 ' pin connected to capacitor
codelen CON 5 ' length of combo
lockrelay CON 0 ' turns on when unlocked
timeout VAR IN7
current VAR Byte
switch VAR Byte
test VAR Byte
OUTPUT lockrelay
LOW lockrelay ' locked!
top:
current=-1 ' before 1st digit
' The code jumps here to advance to the next test digit
advance:
current=current+1 ' look at next digit
IF current=codelen THEN unlock ' or, if done, we got em all
GOSUB resettimer ' reset timer on good key
loop:
GOSUB readsw ' read switches
IF switch=0 THEN testtime ' no switches? Look for timeout
LOOKUP current,[noparse][[/noparse]3,3,1,2,3],test ' get current key to compare for
IF switch=test THEN advance ' right! Advance to next
DEBUG "bad code",CR ' could make an obnoxious beep here
GOTO top ' Start over from beginning
testtime:
IF timeout=0 THEN loop ' still time, so keep looking
IF current=0 THEN top ' don't complain if no entry
DEBUG "timeout",CR
GOTO top
unlock:
DEBUG "unlocked",CR
HIGH lockrelay
GOTO top ' go again for debugging purposes
'Read combo switches to switch variable
' You could customize this in many ways
' SWITCH will equal 0 (no key) or 1, 2, 3 for the 1, 2, or 3 keys
readsw:
switch=INC & 7 ' only 3 switches
switch=switch ^ 7 ' reverse sense (active low->active high)
IF switch=0 THEN noread ' nothing
IF switch<4 THEN readsw_ret ' correct switch 3
switch=3 ' top most switch
readsw_ret:
' now switch=0, 1, 2, or 3
PAUSE 25 ' debounce
readloop:
IF INC <> 15 THEN readloop ' wait for keys to go up
PAUSE 25 ' debounce
DEBUG ?switch
noread:
RETURN
' Reset RC timer
resettimer:
OUTPUT rctrig
LOW rctrig ' discharge capacitor
PAUSE 100 ' give it time
INPUT rctrig
RETURN
Thanks
Stan
--- In basicstamps@yahoogroups.com, "Jon Williams" <jwilliams@p...>
wrote:
> INC is the IO pin group that holds P8, P9, P10 and P11. What the
code
> appears to be doing is reading that group, extracting three of the
pins
> for the variable switch, then retesting the group and continuing
at the
> label "readloop" if all inputs on INC are high.
>
> The inputs to the BASIC Stamp micro are digital: 0 (ground) and 1
(+5v).
> The code indicates active-low inputs. That means the inputs are
> pulled-up to Vdd (+5) through resistors (probably 10K) and a button
> connects between each of the pins and ground. When a button is
open,
> the pin will see "1" (+5v), when the button is pressed the input
will se
> "0" (ground).
>
> This is standard digital stuff. Since you've identified yourself
as
> new, let me suggest you download our "What's A Microcontroller?"
text
> from our web site.
>
> -- Jon Williams
> -- Applications Engineer, Parallax
> -- Dallas Office
>
>
>
Original Message
> From: kingtweeter [noparse][[/noparse]mailto:jamachine@c...]
> Sent: Wednesday, March 31, 2004 6:51 AM
> To: basicstamps@yahoogroups.com
> Subject: [noparse][[/noparse]basicstamps] Newbie Alert !!!!
>
>
> I am trying to understand this but it makes no sense to me at
all.So
> if you got some crayons can you draw me a picture I can
> understand.Here is the first part:
> switch=INC & 7 ' only 3 switches
> switch=switch ^ 7 ' reverse sense (active low->active
high)
>
> Here is the second part:
> IF INC <> 15 THEN readloop
>
> I guess my big question is what value do you apply to the pins
> covered by INC.
>
> Thanks,
> Stan
>
>
>
>
>
>
>
> 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.
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
> This message has been scanned by WebShield. Please report SPAM to
> abuse@p...