Shop OBEX P1 Docs P2 Docs Learn Events
I need to keep score of 3 switches and send this to a display but how — Parallax Forums

I need to keep score of 3 switches and send this to a display but how

ArchiverArchiver Posts: 46,084
edited 2002-09-18 16:43 in General Discussion
Hi, I'm having a small problem. I want to count scores of 3 seperate
buttons. Each button counts from 0 up to 99 and displaying this on a
led-display. I have connected 6 display's where I keep track of the
score. Displaying score is no problem. I have a problem with counting
and displaying at the same time. When I hit a button, it immidiatly
starts counting till 99. (I need to continuosly update my led-display
to make it visseble, thereby I constant pass my button command.)
I cannot make much delay's in the program, or else my display aint
working fine.
How do I count one pushcount at a time ????

Thanks for your thinking about this!!

Greetings, Marko

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2002-09-18 15:23
    First do not just look at the state of the button but rather look for its
    change of state, by waiting till the button is released you eliminate bounce
    and repeat.
    Secondly try reading all 3 buttons at the same time, example assuming they
    are connected to pins 0 - 2 use INA anded with 7 to ignore the fourth bit.

    Lonnie - KF4HAZ -

    From: "smalcor" <Smalcor.AmusementsProducts@
    > Hi, I'm having a small problem. I want to count scores of 3 seperate
    > buttons. Each button counts from 0 up to 99 and displaying this on a
    > led-display. I have connected 6 display's where I keep track of the
    > score. Displaying score is no problem. I have a problem with counting
    > and displaying at the same time. When I hit a button, it immidiatly
    > starts counting till 99. (I need to continuosly update my led-display
    > to make it visseble, thereby I constant pass my button command.)
    > I cannot make much delay's in the program, or else my display aint
    > working fine.
    > How do I count one pushcount at a time ????
    >
    > Thanks for your thinking about this!!
    >
    > Greetings, Marko
  • ArchiverArchiver Posts: 46,084
    edited 2002-09-18 16:43
    >Hi, I'm having a small problem. I want to count scores of 3 seperate
    >buttons. Each button counts from 0 up to 99 and displaying this on a
    >led-display. I have connected 6 display's where I keep track of the
    >score. Displaying score is no problem. I have a problem with counting
    >and displaying at the same time. When I hit a button, it immidiatly
    >starts counting till 99. (I need to continuosly update my led-display
    >to make it visseble, thereby I constant pass my button command.)
    >I cannot make much delay's in the program, or else my display aint
    >working fine.
    >How do I count one pushcount at a time ????
    >
    >Thanks for your thinking about this!!
    >
    >Greetings, Marko

    Do this sort of thing in a loop, a "state machine":

    ' buttons on p0 to p2, active low 0 when pressed
    x0 var nib
    x1 var nib
    xx var nib
    c0 var byte
    c1 var byte
    c2 var byte
    scan:
    x1 = inA ' get state of all 3 buttons
    xx=x1^x0&x1 ' detect changes, bit =1 when button is released
    x0=x1 ' update old state of all 3 buttons
    C0=C0+xx.bit0 ' update counts
    C1=C1+xx.bit1
    C2=C2+xx.bit2
    debug dec C0,tab,dec C1, tab, dec C2, CR ' to display
    goto scan ' over and over


    I hope that helps

    -- Tracy
Sign In or Register to comment.