Shop OBEX P1 Docs P2 Docs Learn Events
Questions. — Parallax Forums

Questions.

MRMR Posts: 46
edited 2009-03-12 13:59 in BASIC Stamp
I need help understanding something.

I have a button connected on pin 7 of the Aux IO.

I have a common anode 7 segment display connected to pins 0-6

What I want the program to do is step up a digit each time I press the button.

Currently when I execute this program it counts from 0-9 then stops. This is not what I want.

For example if I press the button once it should read zero one the display. If I press the button two times it should read 1.

Question 2.

What is the difference between DIRS and OUTS? I don't get how the manual explained it.

Question 3.

I want to make a simple keypad using button command. If pin 1 is pressed it will show a 1. etc et. all.
how would I do this?



Here is the code


' {$STAMP BS2p}
' {$PBASIC 2.5}
AUXIO
'
[noparse][[/noparse] Program Description ]
'
' Displays decimal digits (0 - 9) on a 7-Segment display connected to
' P0-P7. This program will work, unmodified, on any BS2-family module.
'
[noparse][[/noparse] I/O Definitions ]
Segs VAR OUTL ' Segments on P0 - P7
SegsDirs VAR DIRL ' DIRS for segments
'
[noparse][[/noparse] Variables ]
idx VAR Nib ' counter variable
bt VAR Byte
'
[noparse][[/noparse] EEPROM Data ]
' .GFEDCBA
'
Digit0 DATA %11000000
Digit1 DATA %11111001
Digit2 DATA %10100100
Digit3 DATA %10110000
Digit4 DATA %10011001
Digit5 DATA %10010010
Digit6 DATA %10000011
Digit7 DATA %11111000
Digit8 DATA %10000000
Digit9 DATA %10011000
'
[noparse][[/noparse] Initialization ]
Reset:
SegsDirs = %01111111 ' make outputs for LEDs
Delay CON 300
'
[noparse][[/noparse] Program Code ]
Main:
DO
AUXIO
BUTTON 7,0,255,255,bt,1,GO
LOOP

go:
DO
FOR idx = 0 TO 9 ' loop through digits
READ (Digit0 + idx), Segs ' move pattern to display
PAUSE Delay
NEXT
GOSUB main
LOOP

Comments

  • -ljl--ljl- Posts: 1
    edited 2009-03-12 13:59
    I'll try to answer your question 2

    The I/O pins circuit might look something like the diagram i attached.

    Left section (OUT) means outside of basicstamp microcontroller·and Right (IN) means the inside of it. Both·DIRA and·OUTA·act like switches
    which·are programmable. If you set your DIR switch to HIGH( the·lower position of the DIR switch), you are connecting P0 ( pin 0 ) to the
    OUT switch which also means that you are now setting pin0 as output mode. The output signal·of Pin0 (high or low) will depend on whether
    you set the OUT switch to High (+3.3v) or Low(0v).

    for e.g.

    DIR0 = 1
    OUT0 = 1 ' pin0 high

    But for your case, you need Pin0 in INput mode. so instead of setting DIR0=1, you set DIR0=0 which will connect your pin0 to INa switch as shown in· diagram. INa switch will receive the signal input to pin0.

    The diagram attached was used to explain the·propeller chip·but the concept will be the same.

    For question 3,
    Do you mean when·you press pin1 it will show (0000001)
    ······································· pin2·
    (0000010)
    ········································pin3
    (0000011)
    ·in·your 7 segment display(maybe from pin 8 to 14)

    Were you able to detect the button pressed? if yes,

    then your program will be something like...

    DIR1=0
    DIR2=0
    DIR3=0
    ·.
    ·.
    ·.
    DIR7=0

    DIR8=1
    ·.
    ·.
    DIR14=0

    OUT8=0
    OUT9=0
    OUT10=0
    .
    .
    .
    .


    IF·"button pressed on·pin1"· THEN skip00
    skip00:OUT14=1
    GOTO skip1
    skip1: IF " button pressed on pin2"·THEN skip01
    skip01: OUT13=1
    GOTO skip2
    skip2: IF·" button pressed on pin3"·THEN skip02
    skip02: OUT13=1
    ··········OUT14=1
    GOTO...............
    1218 x 686 - 27K
Sign In or Register to comment.