Shop OBEX P1 Docs P2 Docs Learn Events
Dimming and Brightening an LED — Parallax Forums

Dimming and Brightening an LED

DJmartDJmart Posts: 3
edited 2006-06-02 21:24 in BASIC Stamp
How exactly, would I be able to code up a program, that will be able to make an LED very bright, to very dim or off?

In class we did a ramping program, for servos, but I can't seem to get it to work, even by changing the IO pins.

The LED's are on PIN 0 if that helps.


Thanks a bunch fellas

P.S Sorry for a request as first post freaked.gif

Comments

  • cicacica Posts: 11
    edited 2006-06-02 20:18
    DJmart-

    Do you need three states: bright, dim, off? Or do you need a variable brightness? If it's the first case, you could power the same LED with two pins and use different resistors. For example. If you require a 220 ohm resistance for full brightness, you could use a 440 ohm resistor off P0 and a second 440 ohm resistor tied to P1. Then when you want full brightness, you could turn on both P0 and P1, but if you wanted it dimmer, you would just turn on 1 pin. You could vary the resistance to allow for just P0 to be brighter than just P1., etc.

    You might need to add diodes so you don't feedback into the other pin, but that's a question better left for someone more knowledgeable than myself.

    -Tom
  • A.C. fishingA.C. fishing Posts: 262
    edited 2006-06-02 20:56
    Well, you can always attach a servo to a potimeter...(my way)
    Just experiment with some high and low commands.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

    Somebody said...
    -Never Underestimate the power of human stupidity.
    ·
  • Ryan ClarkeRyan Clarke Posts: 738
    edited 2006-06-02 20:58
    You could PWM an LED for different duty cycles, producing varying brightness levels.

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    x VAR Byte
    
    DO
      FOR x = 0 TO 255
        PWM 15, x, 1
      NEXT
      FOR x = 255 TO 0
        PWM 15, x, 1
      NEXT
    
    LOOP
    
    END
    
    




    There is a simple code to fade an LED on and off...

    You can always play with settings, etc, to get different effects.

    Ryan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Ryan Clarke
    Parallax Tech Support

    RClarke@Parallax.com

    Post Edited (Ryan Clarke (Parallax)) : 6/2/2006 9:02:46 PM GMT
  • DJmartDJmart Posts: 3
    edited 2006-06-02 21:11
    PERFECT!!!

    THank you VERY much for the quick reply!

    EDIT:
    is there a way i can increase the speed. Like so it does the dim speed, but loops quicker?

    Post Edited (DJmart) : 6/2/2006 9:18:22 PM GMT
  • Ryan ClarkeRyan Clarke Posts: 738
    edited 2006-06-02 21:12
    No problem. Don't forget to include the appropriate current limiting resistor in series with your LED~

    Ryan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Ryan Clarke
    Parallax Tech Support

    RClarke@Parallax.com
  • Ryan ClarkeRyan Clarke Posts: 738
    edited 2006-06-02 21:20
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    x VAR Byte
    
    DO
      FOR x = 0 TO 255  STEP 5
        PWM 15, x, 1
      NEXT
      FOR x = 255 TO 0   STEP 5
        PWM 15, x, 1
      NEXT
    
    LOOP
    END
    



    You can change the step speed, or you can change the ranges that x goes through-

    Ryan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Ryan Clarke
    Parallax Tech Support

    RClarke@Parallax.com
  • DJmartDJmart Posts: 3
    edited 2006-06-02 21:22
    Man, that works soooo great, thank you sooo much. Hopefully I can think of some other cool things to do with the "step" command.

    I wish i had learned that command weeks ago!
  • Ryan ClarkeRyan Clarke Posts: 738
    edited 2006-06-02 21:24
    Note that in PBASIC, you don't have to use a 'negative step' to count down (in many languages you do)- PBASIC figures out that 20 to 10 is counting down, and steps accordingly.

    Ryan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Ryan Clarke
    Parallax Tech Support

    RClarke@Parallax.com
Sign In or Register to comment.