LED ON and OFF with 2 Push button switches


Closed Thread
Results 1 to 16 of 16

Hybrid View

  1. #1
    Join Date
    Apr 2013
    Posts
    3


    Did you find this post helpful? Yes | No

    Default Re: LED ON and OFF with 2 Push button switches

    Hi Guys thanks for all the inputs.
    I actually need to use a pic like the 16f128 etc because the actual application has 4 inputs (in other words 4 inputs that will give me a 5v high signal independent from each other). Once any of these inputs are triggered a corresponding LED must then switch on.(in other words input 1 must switch on LED 1, input 2 must switch on LED 2, input 3 must switch on LED 3, input 4 must switch on LED 4) I then need to have 4 separate push button switches to cancel the corresponding LED's - one for each LED.
    So I was trying to use the 12f675 just to see if I can get it to work with one push button as an input to switch-on a LED and then another pushbutton to switch-off the LED but am battling to get it right.
    Any help will be appreciated

    Thanks a lot

    Willem

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: LED ON and OFF with 2 Push button switches

    Hi,

    > Any help will be appreciated

    In an effort help you understand what's wrong with your original code I tried to give you some advice in my previous response but apparently that didn't help, so....

    For two buttons and one LED:
    Code:
    Main:
    
      If PB1 = 1 THEN   ' Button 1 is pressed 
        HIGH LED1   ' Turn on LED 1
      ENDIF
    
      IF PB2 = 1 THEN    ' Button 2 is pressed
        LOW LED1    ' Turn off LED 1
      ENDIF
    
    Goto Main
    That's it, rinse and repeat for as many buttons and LEDs as you want.

    /Henrik.

  3. #3
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: LED ON and OFF with 2 Push button switches

    I don't comprestand why you're using a PIC. Transistors or relays will be easier than a PIC for just switching on and off LEDs.

    If you're stuck on using a PIC I'm betting you could use a 12F675 and I'm wondering if this will work. Why can't you make a voltage divider and set a pin at 1/2 of VDD which should be ambiguous with the port set to digital. Then you could monitor the same input pin for a high or low. This way you could use two pins for four inputs and have the other 4 outputs free for your LEDs. Well, you only need 3 ports to switch 6 LEDs but that's another thread.

    Caveat is I've never tried it and wonder if it will work. If I get time I'll throw it together today and see if it works.

Similar Threads

  1. Push button on PIC16F887
    By menta in forum General
    Replies: 21
    Last Post: - 25th June 2008, 07:47
  2. 12f629 push button & LED
    By yankee in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 10th February 2006, 01:45
  3. Button Push within 3 second Window
    By Tissy in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 22nd December 2005, 10:06
  4. push button problem
    By ngeronikolos in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 2nd June 2005, 19:44
  5. Push Button 'Menu' to Choose Variable.
    By Tissy in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 10th March 2005, 07:00

Members who have read this thread : 1

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