button input


Closed Thread
Results 1 to 15 of 15

Thread: button input

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

    Code:
    IF (DIP = 0) AND (BUT = 1) THEN SOMETHING
    IF (DIP = 1) AND (BUT = 1) THEN SOMETHING ELSE
    Dave
    Always wear safety glasses while programming.

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Not as elegant as Dave's... but why do it in one line when you can do it in ten (Ski is not allowed to answer that one)...


    Code:
    	PushButton var PortB.0		' Low when Pressed
    	DIPSwitch var PortB.1 		' Low when ON
    	LED var PortB.2
    
    	TRISB=%00000011
    	Low LED				' Start with LED OFF
    
    Loop:	If PushButton=0 then		' Check for Button Press
    		If DIPSwitch=0 then 	' Check for Options
    			High LED	' Turn ON LED with Button Press...
    			While PushButton=0:Wend
    					' Wait here as long as Button pressed
    			Low LED 	' then turn OFF LED
    			else
    			Toggle LED	' Toggle LED at each Button Press
    			While PushButton=0:Wend
    					' Wait here until finger released from Button
    			endif
    		endif
    	Goto Loop
    
    	End

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Melanie View Post
    Not as elegant as Dave's...
    Not sure how to take that
    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    Sep 2006
    Posts
    42


    Did you find this post helpful? Yes | No

    Default

    Code:
    	PushButton var PortB.0		' Low when Pressed
    	DIPSwitch var PortB.1 		' Low when ON
    	LED var PortB.2
    
    	TRISB=%00000011
    	Low LED				' Start with LED OFF
    
    Loop:	If PushButton=0 then		' Check for Button Press
    		If DIPSwitch=0 then 	' Check for Options
    			High LED	' Turn ON LED with Button Press...
    			While PushButton=0:Wend
    					' Wait here as long as Button pressed
    			Low LED 	' then turn OFF LED
    			else
    			Toggle LED	' Toggle LED at each Button Press
    			While PushButton=0:Wend
    					' Wait here until finger released from Button
    			endif
    		endif
    	Goto Loop
    
    	End
    Thanks a lot..
    there are 6outputs and 8inputs available in my project. as per above explanation need 12 input ports to enable all.(6for dip and 6 for push buttons) is there any way that to create a dip switch combination, with 2 dip switches..

    Regards.

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


    Did you find this post helpful? Yes | No

    Default

    Put one dip on a port. Then read the whole PORT into a variable.
    Code:
    dip1=PORTB
    dip2=PORTC
    Read this thread, post #2
    http://www.picbasic.co.uk/forum/show...ight=read+port
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Sep 2006
    Posts
    42


    Did you find this post helpful? Yes | No

    Default

    Thank you. I tried to understand from the PBP manual but i couldnt succeed. could you pls give some code Example.

    Regards.

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by naga View Post
    could you pls give some code Example.
    The code example is right there in the last post!

  8. #8
    Join Date
    Oct 2008
    Posts
    8


    Did you find this post helpful? Yes | No

    Default HI can we put a PWM command in?

    Hi this program is great that Mel has writen can we use the same program but soon as the button is pressed led go high for 500 / 1/2 second then PWM 50 duty and 5KHz and then then pwm stop when button is released?

    i have the program working but the PWM hangs on after the button is off

    PushButton var PortA.1 ' Low when Pressed
    DIPSwitch var PortA.1 ' Low when ON
    LED var PortB.0

    TRISA=%1111
    TRISA=%0000
    Low LED ' Start with LED OFF

    Loop: If PushButton=0 then ' Check for Button Press
    If DIPSwitch=0 then ' Check for Options
    High LED ' Turn ON LED with Button Press...
    PAUSE 500

    PWM 0,50,500

    While PushButton=0:Wend
    ' Wait here as long as Button pressed

    Low LED ' then turn OFF LED
    else
    Toggle LED ' Toggle LED at each Button Press
    While PushButton=0:Wend

    ' Wait here until fingerreleased from Button
    endif
    endif
    Goto Loop

    End

Similar Threads

  1. RB0 + Internal Pullup + Interrupt
    By Freman in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 10th August 2009, 11:11
  2. button input: what is necessary for a proofed behaviour
    By mischl in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 8th November 2007, 15:45
  3. Timing input pulses and re-outputting them
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 28th February 2007, 01:50
  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 : 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