multi functions button press


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2009
    Posts
    36

    Angry multi functions button press

    i need help i wanna use 1 button to multi fonction things,ex. when i press the 1st time to swich led 1 in portb.0 2nd time swich led 2 in portb.1 so on or ,i use variables, this is my code but it doesnt work, if there another way please help

    define osc 4

    symbol led_1 = portb.0
    symbol led_2 = portb.1
    symbol led_3 = portb.2
    button var porta.0
    b0 var byte
    portb = 0
    porta.0 = 1
    main:
    count button,1000, b0
    if button = 0 then
    high led_1
    pause 100
    low led_1
    if button = > 0 then
    high led_2
    pause 100
    low led_2
    if button = ??? then
    high led_3
    pause 100
    low led_3
    goto main

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Have you tried to read B0 variable instead?

    Does it need to have a timeout? If so, probably not a bad idea to process COUNT only when you press on your push button.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Apr 2009
    Posts
    36


    Did you find this post helpful? Yes | No

    Default

    hi mister_e im new in pbp i will try many ways and i hope someone here has a good ideas how it works ,thnks mister_e.

  4. #4
    Join Date
    May 2007
    Location
    Area 71
    Posts
    52


    Did you find this post helpful? Yes | No

    Default

    You should use temporary counter like this:

    start:
    button blabalabla... click
    if a= 1 then blablabla
    etc..
    goto start:

    click:
    a=a+1
    goto start

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by malwww View Post
    i need help i wanna use 1 button to multi fonction things,ex. when i press the 1st time to swich led 1 in portb.0 2nd time swich led 2 in portb.1 so on or ,i use variables, this is my code but it doesnt work, if there another way please help

    define osc 4

    symbol led_1 = portb.0
    symbol led_2 = portb.1
    symbol led_3 = portb.2
    button var porta.0
    b0 var byte
    portb = 0
    porta.0 = 1
    main:
    count button,1000, b0
    if button = 0 then
    high led_1
    pause 100
    low led_1
    if button = > 0 then
    high led_2
    pause 100
    low led_2
    if button = ??? then
    high led_3
    pause 100
    low led_3
    goto main

    Don't you need some ENDIF statements through the code ?

  6. #6
    Join Date
    May 2009
    Location
    USA
    Posts
    16


    Did you find this post helpful? Yes | No

    Default

    You should initialize B0 to be 0 and it's best to use Select Case for this code:
    Code:
    Select Case B0
    	Case 0:
    		high led_1
    		pause 100
    		low led_1
    		B0 = B0 + 1
    	Case 1:
    		high led_2
    		pause 100
    		low led_2
    		B0 = B0 + 1
    	Case Else
    		high led_3
    		pause 100
    		low led_3
    		B0 = 0
    End Select
    Why is the email address verification case sensitive?

  7. #7
    Join Date
    Apr 2009
    Posts
    36


    Did you find this post helpful? Yes | No

    Default

    thank you GoldStar i will try it out and i post the result.

Similar Threads

  1. Giving power to MCU upon button press - Good Idea?
    By financecatalyst in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 21st July 2009, 07:34
  2. Using Sleep
    By elec_mech in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 17th August 2008, 04:05
  3. Button press and press & hold how to ?
    By GrandPa in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 22nd August 2007, 03:37
  4. 3 HPWM channels
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th April 2006, 02:43
  5. Code check -- button not working
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 2nd March 2006, 22:43

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

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