Switch in PIC BASIC HELP!!!!


Closed Thread
Results 1 to 35 of 35

Hybrid View

  1. #1
    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.

  2. #2
    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 02:35.

  3. #3
    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.

  4. #4
    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 ?

  5. #5
    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!

  6. #6
    Join Date
    Sep 2009
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    Hello.
    Can you please give us a bit more detailed description of what are you trying to achieve. In the meantime you could try this:

    Code:
    led_tm	var word
    led	var byte
    indx	var byte
    dbc	var byte
    led_f	var bit
    
    symbol 	key=porta.2
    
    poke $1F,7	'turn off comparator
    poke $9F,0	'turn off voltage reference
    
    porta=0: portb=0
    trisa=%00010100
    trisb=%00000000
    pause 500
    
    led_f=0: led_tm=0: indx=3
    
    
    
    MAIN:
    pause 1
    if key=0 then dbc=dbc+1		'use this if porta.2 is pulled high
    'if key=1 then dbc=dbc+1	'use this if porta.2 is pulled low
    if dbc=70 then gosub SWITCH_LED
    if dbc>72 then dbc=72
    if key=1 then dbc=0		'use this if porta.2 is pulled high
    'if key=0 then dbc=0		'use this if porta.2 is pulled low
    
    led_tm=led_tm+led_f
    if led_tm=500 then
    	toggle led
    	led_tm=0
    	endif
    goto MAIN
    
    
    SWITCH_LED:
    indx=indx+1
    if indx>2 then indx=0
    lookup indx,[1,2,3],led
    toggle led
    led_f=1
    return

  7. #7
    Join Date
    May 2010
    Posts
    43


    Did you find this post helpful? Yes | No

    Default

    Thanks so much,Grinder,for your help!!!

    I try your code,and working good,just what I wont to do in my project,when I press button in PORTA.2, to change program,and still in same program,
    and your code do it that!

    But,can,you ex plane me,what I must do, which peace,of your code,I must change,
    if I like to change, which port I like to be low,of high,I mean because I like to make some ,to combinations of led,to high,or low,to I do it myself!

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


    Did you find this post helpful? Yes | No

    Default

    To be fair, paste up your complete code as it is and then people can see what you want to do and hopefully post a corrected version for you. To ask for help and only post up cryptic bits of code makes it hard to provide the support you are seeking

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