Switch in PIC BASIC HELP!!!!


Closed Thread
Results 1 to 35 of 35

Hybrid View

  1. #1
    Join Date
    May 2010
    Posts
    43


    Did you find this post helpful? Yes | No

    Default

    Thanks,for help,but can you give me one more answer!

    I write this code:

    ButtonPressCounter var byte

    SWITCHLOOP:
    IF PORTA.2 = 0 THEN
    IF ButtonPressCounter = 3 THEN ButtonPressCounter = 0
    ButtonPressCounter = ButtonPressCounter + 1
    IF ButtonPressCounter = 1 THEN GOSUB Program1
    IF ButtonPressCounter = 2 THEN GOSUB Program2
    IF ButtonPressCounter = 3 THEN GOSUB Program3
    ENDIF
    GOTO SWITCHLOOP:

    Program1:
    high portb.1
    PAUSE 500
    LOW PORTB.1
    PAUSE 500

    RETURN

    Program2:
    high portb.2
    PAUSE 500
    LOW PORTB.2
    PAUSE 500
    RETURN

    Program3:
    high portb.3
    PAUSE 500
    LOW PORTB.3
    PAUSE 500
    RETURN

    is Ok,code working,
    but how I do it,when I switch button,to change program,and stay work in this some of this program?

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    but how I do it,when I switch button,to change program,and stay work in this some of this program?
    Sorry, but I do not understand the question.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    May 2010
    Posts
    43


    Did you find this post helpful? Yes | No

    Default

    I try ex plane,my question!
    I mean!

    I need when I press button one time,
    then in my case go to program1,
    and still working in program1!

    When I press button second time then
    go to program2,
    and still working in program2,

    When I press button 3.rd time then
    go to program3,
    and still working in program3,......

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Maybe...
    Code:
    SWITCHLOOP:
    IF PORTA.2 = 0 THEN ButtonPressCounter = ButtonPressCounter + 1
    IF ButtonPressCounter = 1 THEN GOSUB Program1
    IF ButtonPressCounter = 2 THEN GOSUB Program2
    IF ButtonPressCounter = 3 THEN GOSUB Program3
    IF ButtonPressCounter = 4 THEN ButtonPressCounter = 0
    ENDIF
    GOTO SWITCHLOOP:
    maybe not... See what happens.
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    May 2010
    Posts
    43


    Did you find this post helpful? Yes | No

    Default

    Thanks,for your help,
    but not working!

    I need this program, because I try make program for some light show,when I press button,to change program,and still working,in some of this my program!
    Last edited by dragan77; - 18th May 2010 at 01:35.

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Are we seeing the whole code?
    Have you turned any ANALOG off?
    http://www.picbasic.co.uk/forum/showthread.php?t=561

    And if that does not work tell what is happening.
    Dave
    Always wear safety glasses while programming.

  7. #7
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by dragan77 View Post
    Thanks,for your help,
    but not working!

    I need this program, because I try make program for some light show,when I press button,to change program,and still working,in some of this my program!
    Post your complete code (all lines) and you might get a better response.

    The code I posted works the way you want to.. but requires two buttons... is that such a problem ?

  8. #8
    Join Date
    May 2010
    Posts
    43


    Did you find this post helpful? Yes | No

    Default

    First,THANKS ALL FOR HELP!!!

    THIS IS CODE i WILL TRY TO MODIFIED,

    ButtonPressCounter var byte

    SWITCHLOOP:
    IF PORTA.2 = 0 THEN
    IF ButtonPressCounter = 3 THEN ButtonPressCounter = 0
    ButtonPressCounter = ButtonPressCounter + 1
    IF ButtonPressCounter = 1 THEN GOSUB Program1
    IF ButtonPressCounter = 2 THEN GOSUB Program2
    IF ButtonPressCounter = 3 THEN GOSUB Program3
    ENDIF
    GOTO SWITCHLOOP:

    Program1:
    high portb.1
    PAUSE 500
    LOW PORTB.1
    PAUSE 500

    RETURN

    Program2:
    high portb.2
    PAUSE 500
    LOW PORTB.2
    PAUSE 500
    RETURN

    Program3:
    high portb.3
    PAUSE 500
    LOW PORTB.3
    PAUSE 500
    RETURN

    This code work good,but,I need just when I press my button,then,
    still working on some on this may program,

    program1,program2,program3!!!

    I do not how I make some changes,that will be working!

Members who have read this thread : 0

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