button input


Closed Thread
Results 1 to 15 of 15

Thread: button input

Hybrid View

  1. #1
    Join Date
    Sep 2006
    Posts
    42

    Default button input

    Dear All,Looking for some code help.

    portb.0 connected to press button via dip switch. what i want is:

    if DIP SW = off and button is pressed then OUTPUT = toggle.(Latch)
    if DIP SW = on and button is pressed then OUTPUT = Momentry(as long as the button is pressed)
    IS it possible?

    Thanks.

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

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

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

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

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

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

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