Shop OBEX P1 Docs P2 Docs Learn Events
LED light control question — Parallax Forums

LED light control question

Bibliophile6Bibliophile6 Posts: 9
edited 2007-02-13 21:31 in BASIC Stamp
·Well now I have a good knowledge with working with LED's.
However what I would like to know, how·can I press a button to turn the light on, but when I let go; the light slowly fades off?

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2007-02-13 21:01
    The classic way to do this is with a PWM that starts at 100% and 'fades' to 0% over a period of time.

    On the BS2, I'd implement that with a PULSOUT command, though I suppose there's several ways to implement this.
  • boeboyboeboy Posts: 301
    edited 2007-02-13 21:03
    You can use a capacitor. It would charge when you press the button and when you let go it would discharge and the led would slowly fade.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    lets see what this does... KA BOOM (note to self do not cross red and black)
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-13 21:04
    An LED doesn't dim well. You can vary the amount of current through it and it will get dimmer, but it's not linear and relatively hard to control. Usually, these are made to appear dim by turning them on and off rapidly so the average amount of time they're on varies. Your eyes average the light level. Try using the PULSOUT statement to produce pulses varying from 100us to 10ms in width with a PAUSE 1 between successive pulses for a 1ms pause. You'll get on/off ratios from 1:10 to 10:1. See what that looks like. Figure out what you need to do to get the light to fade the way you want.
  • Bibliophile6Bibliophile6 Posts: 9
    edited 2007-02-13 21:22
    Ok I tried this thing with Page· 85, something else happened. One of the lights work, I press one of the buttons - light is dim, I keep holding it and press the other. Light flashed brighter, as the other light doesn't do a thing!?





    ' {$STAMP BS2}
    ' What's a Microcontroller - PushbuttonControlledLed.bs2
    ' Check pushbutton state 10 times per second and blink LED when pressed.

    ' {$PBASIC 2.5}
    DO
    · DEBUG HOME
    · DEBUG ? IN4
    · DEBUG ? IN3
    IF (IN3 = 1) THEN
    ··· HIGH 14
    ··· PAUSE 50
    ELSEIF (IN4 =1) THEN
    ··· PULSOUT 14,550····<
    My Corrections that I did, What did I do wrong?
    ··· PAUSE 50
    · ELSE
    ··· PAUSE 50
    · ENDIF
    · LOW 14
    · LOW 15
    · PAUSE 50
    LOOP
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-13 21:31
    I would really strongly suggest that you work through the examples in the tutorial. They're designed to introduce concepts one at a time with examples and variations to illustrate points.

    You made a change in the program. Look carefully at what you did. Compare it to what you had originally. I think you'll be able to figure out what's happening.
Sign In or Register to comment.