Shop OBEX P1 Docs P2 Docs Learn Events
dimming a led — Parallax Forums

dimming a led

guydbguydb Posts: 29
edited 2007-11-02 10:47 in BASIC Stamp
hi,
any suggestions as to how to dim a led with the stamp?
thanks,
guy

Comments

  • CrashmdcCrashmdc Posts: 8
    edited 2007-11-01 14:18
    You could use the PULSOUT command and change the duty cycle, or similarly write a loop that turns it on and off quickly for a certain duration. If you want to run other code while the led is dimmed, you could have an output of the stamp control a timer circuit to keep it at that level.

    Regards,
    Mike
  • Mike GreenMike Green Posts: 23,101
    edited 2007-11-01 14:25
    The PWM statement will let you produce an adjustable light output. Read the section in the manual on it and try it.
    Unfortunately, the Stamp can't do anything else while it's executing the PWM statement, but you could do other
    brief things as long as your program spends most of its time doing the PWM.

    Here's one example of a program that does LED fading with some motor control: http://forums.parallax.com/showthread.php?p=682581.
  • stephenwagnerstephenwagner Posts: 147
    edited 2007-11-01 15:17
    Guy dB,

    Read the Basic Stamp 1 application note "Fun With Trains" application 21.

    It is a very cleaver way of creating a continuous PWM signal within a loop.

    The application outputs three (3) unique PWM signals Continuously to modulate three (3) electric train motors.

    If you create an 8 bit byte variable, and add a duty cycle of 0 to 255 (0% to 100%) to itself in a loop, output the variable.bit8 to a pin, clear variable.bit8 to 0, you will have created a continuous PWM signal. The higher the duty cycle, the more times variable.bit8 will be a logic 1.

    http://www.parallax.com/dl/appnt/stamps/bs1Appnotes.pdf

    Also read this application from EME System. The code mimics the Parallax PWM statement.

    http://www.emesystems.com/BS2PWM.htm.


    Stephen J Wagner
  • guydbguydb Posts: 29
    edited 2007-11-01 20:51
    thank you for the replies, I certainly will check out the servo application...PWM still is a problem as ideally I'd have something else running whil one or more leds are shingin on at a specific intensity...but I'll read the examples and try to figure something out
  • stephenwagnerstephenwagner Posts: 147
    edited 2007-11-01 23:32
    Guy dB.

    You can insert several the·code examples from the Trains application note or from EME systems into your code that is allready running. However, at some point the LEDs may start to flicker. Insert more examples as required.

    SJW
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2007-11-02 03:35
    ·
    ' {$PBASIC 2.5}
    ' {$STAMP BS2}
    
    
    cycles  VAR Byte
    bv      VAR Byte
    ontime  VAR Byte
    offtime VAR Byte
     
    OUTPUT 1
    OUT1 = 0
     
    init:
     ontime = 1
     offtime = 9
     
    duty_var:
     FOR bv = 0 TO 7
      FOR cycles = 0 TO 20
      OUT1 = 1
      PAUSE ontime
      OUT1 = 0
      PAUSE offtime
      NEXT                   ' next cycles
      ontime = ontime + 1
      offtime = offtime - 1
      NEXT                    ' next bv
     
    GOTO init
    
  • guydbguydb Posts: 29
    edited 2007-11-02 10:47
    thanks for that bit of code as well.
    but in the end I think I have my solution (I should have mentioned that I was looking for optocoupling, controlling the leds from the stamp and needing various levels of brightness), I will use 74HC595's and have the number of leds lit to take care of brightness (ok, only 8 per 74, but working with colour combinations and positioning towards the LDR might give more gradation).
Sign In or Register to comment.