Shop OBEX P1 Docs P2 Docs Learn Events
Stamp Inputs — Parallax Forums

Stamp Inputs

ArchiverArchiver Posts: 46,084
edited 2000-11-10 09:39 in General Discussion
Hello Everyone,

Application:
I'm using two stamp pins as inputs. When pin 0 is high and pin 1 is
high, I'm storing a 3. When pin 0 is high and pin 1 is low then I'm
storing a 1. When pin 0 is low and pin 1 is high, I'm storing a 2.

Problem:
Storing 3 works okay, but I'm getting unreliable results when
checking for 1 or a 2.

Hook-up:
I have a 22K resistor going to pin 0.
I have a diode going from ground to pin 0. (banded end to pin)
I have a SPST momentary switch also going to pin 0. (+5V)
(The same thing is duplicated for pin 1 above)
I have a diode going to the pin 0 circuit with and another diode
going to the pin 1 circuit, both diode with the non-banded ends
conncected to the thrid SPST momentary switch. This swith is also
connected to ground with a diode.

Successful When:
If I press the momemtary SPST switch on pin 0 without pressing the
other two switches, a '1' is registered...etc.
Pressing the thrid switch works great. The third switch makes pin 0
and pin 1 both high.

Question:
Is the probem in the code, or in the hook-up?

Code:
'I have tried many code variations, this is not the most efficient
but simply a desperate variation

INPUT 0
INPUT 1

DEBUG "START",CR
START:
'IF IN0=1 AND IN1=1 THEN THREE
IF IN0=1 THEN ONE
IF IN1=1 THEN TWO
'DEBUG "0",CR
GOTO START

ONE:
debug "At One",cr
IF IN1=1 THEN THREE
DEBUG "1",CR
hold1:IF IN0=1 THEN hold1
'PAUSE 1500
GOTO START


TWO:
debug "At Two",cr
IF IN0=1 THEN THREE
DEBUG "2",CR
hold2:IF IN1=1 THEN hold2
'PAUSE 1500
GOTO START

THREE:
debug "At Three",cr
DEBUG "3",CR
hold3:IF IN0=1 AND IN1=1 THEN hold3
'PAUSE 1500
GOTO START

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2000-11-10 09:39
    Your hookup is correct except for both diodes between pins and gnd, not
    necessary.
    Your program is a lot too complicated, see below.

    Input 0
    Input 1 'pins 0 and 1 are inputs
    loop:
    debug dec ? inA & 3 'display input for pins 0 and 1 only
    pause 1500
    goto loop


    Original Message
    From: <Forbesits@y...>
    To: <basicstamps@egroups.com>
    Sent: jeudi 9 novembre 2000 18:57
    Subject: [noparse][[/noparse]basicstamps] Stamp Inputs


    > Hello Everyone,
    >
    > Application:
    > I'm using two stamp pins as inputs. When pin 0 is high and pin 1 is
    > high, I'm storing a 3. When pin 0 is high and pin 1 is low then I'm
    > storing a 1. When pin 0 is low and pin 1 is high, I'm storing a 2.
    >
    > Problem:
    > Storing 3 works okay, but I'm getting unreliable results when
    > checking for 1 or a 2.
    >
    > Hook-up:
    > I have a 22K resistor going to pin 0.
    > I have a diode going from ground to pin 0. (banded end to pin)
    > I have a SPST momentary switch also going to pin 0. (+5V)
    > (The same thing is duplicated for pin 1 above)
    > I have a diode going to the pin 0 circuit with and another diode
    > going to the pin 1 circuit, both diode with the non-banded ends
    > conncected to the thrid SPST momentary switch. This swith is also
    > connected to ground with a diode.
    >
    > Successful When:
    > If I press the momemtary SPST switch on pin 0 without pressing the
    > other two switches, a '1' is registered...etc.
    > Pressing the thrid switch works great. The third switch makes pin 0
    > and pin 1 both high.
    >
    > Question:
    > Is the probem in the code, or in the hook-up?
    >
    > Code:
    > 'I have tried many code variations, this is not the most efficient
    > but simply a desperate variation
    >
    > INPUT 0
    > INPUT 1
    >
    > DEBUG "START",CR
    > START:
    > 'IF IN0=1 AND IN1=1 THEN THREE
    > IF IN0=1 THEN ONE
    > IF IN1=1 THEN TWO
    > 'DEBUG "0",CR
    > GOTO START
    >
    > ONE:
    > debug "At One",cr
    > IF IN1=1 THEN THREE
    > DEBUG "1",CR
    > hold1:IF IN0=1 THEN hold1
    > 'PAUSE 1500
    > GOTO START
    >
    >
    > TWO:
    > debug "At Two",cr
    > IF IN0=1 THEN THREE
    > DEBUG "2",CR
    > hold2:IF IN1=1 THEN hold2
    > 'PAUSE 1500
    > GOTO START
    >
    > THREE:
    > debug "At Three",cr
    > DEBUG "3",CR
    > hold3:IF IN0=1 AND IN1=1 THEN hold3
    > 'PAUSE 1500
    > GOTO START
    >
    >
    >
    >
    >
    >
    >
    >
Sign In or Register to comment.