Shop OBEX P1 Docs P2 Docs Learn Events
Button — Parallax Forums

Button

jeanjean Posts: 21
edited 2006-03-22 21:49 in BASIC Stamp
hi,
I have a BS2Pe and using push-buttons I want the microcontroller to log the entry
This is how I wanted to monitor each button.
Nomally if I dont press any button it should keep looping forever right?... but it doesnt. for some reason some of the buttons think they are pressed and execute the concequent code
I'm starting to doubt that maybe this is not the best way of using the BUTTON command?
any ideas?


check0:
    offset = 0
    BUTTON bu0,  0,     255,   20,    b0ws,  0,      check1
    offset = 0
    RETURN

check1:
    BUTTON bu1,   0,     255,   20,    b1ws,  0,      check2
    offset = 1
    RETURN

check2:
    BUTTON bu2,   0,     255,   20,    b2ws,  0,      check3
    offset = 2
    RETURN

check3:
    BUTTON bu3,   0,     255,  20,    b3ws,  0,      check4
    offset = 3
    RETURN

check4:
    BUTTON bu4,   0,     255,   20,    b4ws,  0,      check5
    offset = 4
    RETURN

check5:
    BUTTON bu5,   0,     255,   20,    b5ws,  0,      check6
    offset = 5
    RETURN

check6:
    BUTTON bu6,   0,     255,  20,    b6ws,  0,      check7
    offset = 6
    RETURN

check7:
    BUTTON bu7,   0,     255,   20,    b7ws,  0,      check8
    offset = 7
    RETURN

check8:
    BUTTON bu8,   0,     255,   20,    b8ws,  0,      check9
    offset = 8
    RETURN

check9:
    BUTTON bu9,   0,     255,   20,    b9ws,  0,      check10
    offset = 9
    RETURN

check10:
    BUTTON bu_ok,   0,     255,   20,    b10ws,  0,      check11
    offset = 10
    isSer = isSer + 1
    IF(isSer = 3) THEN
      GOTO SerialControl
    ELSE
      GOTO here
    ENDIF
    RETURN

check11:
    BUTTON bu_clr,   0,     255,   20,    b11ws,  0,      check12
    GOTO Main
    offset = 11
    RETURN

check12:
    BUTTON bu_can,   0,     255,   20,    b12ws,  0,      check0
    offset = 12
    GOTO Main
    RETURN

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-03-20 03:00
    Perhaps it is because you didn't post the complete code but it seems you have a lot of RETURNs for which there are no GOSUB statements.· Also, even though I would guess the problem is in the code, do you have pull-up resistors connected to each input pin?· You should attach (not paste) your complete code so we can see what is going on.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • jeanjean Posts: 21
    edited 2006-03-20 03:39
    Hi,
    Thank you for the quick reply
    Here is my complete code.
    Basically the code takes in the entries from the user (8digits) and stores them to EEPROM
    my other concern is that my 8-digits entries are 32 bits each which means I wont be able to store that much in my EEPROM
    Cheers, smile.gif
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-03-20 06:35
    According to your code, you only have two of the buttons connected.· The other I/O lines are probably floating and giving false triggers.· Perhaps you should comment out the sections you aren't using in hardware or use pull-up resistors to stop the lines from floating.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • jeanjean Posts: 21
    edited 2006-03-20 16:15
    I see. I should pull-up my pins that I'm not using to make sure they are high.
    My other question is how can I add more memory in odrer to be able to store more entries on the EEPROM?
    Should I use registers? or uMMC controllers?
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-03-20 16:23
    That's an entriely different issue and you should probably start a thread for that.· Besides pull-ups on the unused BUTTON inputs, you should have pull-ups on the ones you are using as well.· Do you have these?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • jeanjean Posts: 21
    edited 2006-03-20 16:36
    yes, I do have pull-ups on the one's I am using.
    One more little question: do you think this is a good algorithm to log entries? my concern was that maybe my algorithm uses too much space.
    Thank you for your help
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-03-20 16:41
    jean,

    ·· I did not analyze how you were storing data.· Just the original issue regarding the inputs.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • jeanjean Posts: 21
    edited 2006-03-20 16:43
    Ok thank you
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-03-20 17:31
    Your code to write to the EEPROM looks straight-forward, but while looking through I see that in your BUTTON section you have also got a few spots where you do a GOTO Main and never reach the RETURN in that routine.· You might want to consider re-structuring your BUTTON block so that you have one valid entry and one valid exit point or you handle the routines on the fly from the main loop without doing them in a subroutine, since these problems make it such that you cannot "RETURN" from the subroutine.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • jeanjean Posts: 21
    edited 2006-03-20 18:29
    ok thanks, I will restructure the BUTTON block to avoid nested branching with no end. cheers
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-03-22 16:57
    Using more than one BUTTON instruction is not very efficient; with a tiny bit of code you can scan/debounce as many inputs as you want and store the results in a single variable; this gives you the additional benefit off handling multi-button presses.· I've attached a program from StampWorks 2.0 that you can expand as required.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • jeanjean Posts: 21
    edited 2006-03-22 21:49
    thank you smilewinkgrin.gif
Sign In or Register to comment.