Pushbutton code routine suggestions?


+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2004
    Location
    Ladysmith on Vancouver Island in BC Canada
    Posts
    173

    Default Pushbutton code routine suggestions?

    Hello

    Lately I've been playing around with some push buttons to create code that will increase and decrease a word sized variable from 0 to 65535 and to do it fairly quickly while maintaining some kind of reasonable control and visual effect. I did manage to write some code that seems to do the job ok but it uses close to 600 words!!! It still needs a little tweaking but otherwise works great. Would anyone here have any routines or suggestions that would accomplish or complement this, that would possibly use less code space? I've included my code as an attachment below. I've tried to implemented a variable pause that changes (speeds-up) while the push button is held down and then, when the button is released (when you get close to the number you want) and re-pressed, then the number up or down will be slowed down. I checked the archives but couldn't find anything that was related to what I'm trying to do here. Any suggestions or comments will be appreciated.

    Thanks
    jessey
    Attached Files Attached Files

  2. #2
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    562

    Smile Use the Button function instead

    Dear Jessey,

    You can do the job more easily using the button function. It handles the debounce , and has an autorepeat feature. Autorepeat delay , and rate are also programmable. You need to create a variable for the button and also make sure that the routine runs in a loop.

    Here is a code example:

    '************************************************* ******************************
    SPEEDSET:

    B1 = 0 : B2 = 0 : LED1 = 0 : LED2 = 0 : LED3 = 0 ' TURN OFF ALL LEDS
    LCDOUT $FE, 1 ' CLEAR THE LCD
    LCDOUT "SET SERVO SPEED" ' SHOW THE SUB-MENU ITEM
    PAUSE 2000 ' CHECK FOR VALID SPEED
    IF SPEED > 127 THEN SPEED = 0
    SPEED_PRESET_LOOP: ' PRESET LOOP
    LCDOUT $FE, $C0,"TRACKSPEED=",DEC SPEED," "
    PAUSE 1 ' SHORT DELAY TO REDUCE LCD FLICKER
    IF HALT = 0 THEN QUIT ' CHECK IF STOP BUTTON HIT THEN QUIT TO MAIN MENU
    BUTTON INCR, 0, 200, 30, B1, 1, SPEED_PLUS ' IF THE INCREMENT BUTTON IS PRESSED (PULLED-UP)
    BUTTON DECR, 0, 200, 30, B2, 1, SPEED_MINUS ' IF THE DECREMENT BUTTON IS PRESSED (PULLED-UP)
    GOTO SPEED_PRESET_LOOP

    SPEED_PLUS: ' ROUTINE TO INCREASE THE SPEED VARIABLE
    SPEED = SPEED + 1
    IF SPEED > 127 THEN SPEED = 0
    GOTO SPEED_PRESET_LOOP

    SPEED_MINUS: ' ROUTINE TO DECREASE THE SPEED VARIABLE
    SPEED = SPEED - 1
    IF SPEED > 127 THEN SPEED = 0
    GOTO SPEED_PRESET_LOOP

    '************************************************* ******************************

    The speedset routine is practically a sub-menu in my application and is entered from a menu choice. B1 and B2 are button variables (byte). Speed is the variable that is modified through the buttons. INCR is an alias for the increment button normally high (pulled- up) and DECR is an alias for the decrement button. Halt is an alias for the Stop button (that lets one quit from the sub-menu or the main-menu)

    Regards
    Sougata

  3. #3
    Join Date
    Apr 2004
    Location
    Ladysmith on Vancouver Island in BC Canada
    Posts
    173

    Default

    Hi Sougata

    Thanks for the suggestion and the sample code, I'll give it a try and see what I can accomplish using the Button command.

    Thanks Again
    jessey

Similar Threads

  1. TSA5512/5511 code for PIC16F877/84
    By Marin in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 24th August 2013, 06:16
  2. PIC BASIC TLC5940 code
    By eletrokat in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 8th May 2010, 21:01
  3. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  4. Replies: 14
    Last Post: - 26th September 2007, 05:41
  5. Re-Writing IF-THEN-AND-ENDIF code?
    By jessey in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 18th August 2006, 17:23

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts