Shop OBEX P1 Docs P2 Docs Learn Events
Sharing Switch and LED on one pin. — Parallax Forums

Sharing Switch and LED on one pin.

tonyp12tonyp12 Posts: 1,951
edited 2013-01-14 21:31 in General Discussion
The button is not pressed very often and if the light comes on by itself when button is pressed is OK.

If just using the single 230ohm (led) resistor and no 10k pull-up/down for the switch is a bonus point.

If in very short intervals turning the pin to a input to read the switch and that will turn off the LED is OK.
But if holding down switch will not turn off or on the LED is extra bonus points.

Comments

  • kwinnkwinn Posts: 8,697
    edited 2013-01-14 19:37
    I am assuming this is for a prop at 3.3V but confirmation would be nice. Led color (forward voltage) is also an important factor in the design.
  • tonyp12tonyp12 Posts: 1,951
    edited 2013-01-14 19:58
    yes Prop is 3.3v, if forward voltage is determing the design I will get red, green or blue.(2v to 3v FV)
  • kwinnkwinn Posts: 8,697
    edited 2013-01-14 20:46
    I can come up with 4 ways to connect the led, resistor, and pb switch to the prop I/O pin to allow the state of the switch to be read but all of them cause the led to turn on or off when the switch is pressed.
  • CircuitsoftCircuitsoft Posts: 1,166
    edited 2013-01-14 21:31
    {{
                       
          └┐          │
              100     
      PIN ──╋────────┘
              1M    10K
             
    }}
    
    CON
      PIN = 4
      
    PUB Test
      DIRA[PIN]~~
    
      repeat
        waitcnt(cnt+CLKFREQ/50)
        DIRA[PIN]~
        waitcnt(cnt+CLKFREQ/1000) ' Give the I/O some time to settle since turning off the output
        OUTA[PIN] := !INA[PIN]
        DIRA~~
    

    This circuit will pull the I/O pin to a logic low, but won't draw enough current to light the LED. If the pin is pulled low by software, it will light the LED. Pressing the button will turn it into a pull-up, but the LED will still be lit by pulling it down.
Sign In or Register to comment.