November 21, 2024, 07:13:28 AM

News:

You can now use Vixen to program your Prop-1 and Prop-2 controllers!  Get started quickly and easily, without having to learn PBASIC.  Details in the Library forum.


LED Dimmer

Started by gneirynck, September 25, 2019, 08:40:57 AM

Previous topic - Next topic

gneirynck

Does the Prop-1 have any variable output (0-12v) that can be used to dim an LED?  I'm looking to fade one LED on and another one off for a Pepper's Ghost effect.
Thanks
-Gary


gneirynck

Hey Jeff,
Thanks for the links.  This did help.  I mostly have this working.  Here is the code I have with the LEDs connected to Out 6 & Out 7.

SYMBOL  pin              = B2
SYMBOL  level1           = B3
SYMBOL  level2           = B4

' -----[ Program Code ]----------------------------------------------------

Main:

    HIGH 6
    LOW 7
    PAUSE 2000

    FOR level1 = 255 TO 1 STEP -1
      level2 = 255-level1
      PWM 6, level1, 1
      PWM 7, level2, 1
      PWM 6, level1, 1
      PWM 7, level2, 1
    NEXT

    HIGH 7
    PAUSE 3000
  GOTO Main

I added the PWM lines twice to slow down the fade.  Using a PAUSE only makes it blink.  The problem I am having is that when the LED is set to HIGH has 12V applied.  However, as soon as the fade routine starts, the brightness drops and the voltage seems to drop to 5V and then fades to 0.  How can I make this fade from 12V to 0.

Jeff Haas

Hi Gary,

First, there's a bug in your code that could be causing issues.  On these lines:

      PWM 6, level1, 1

The "1" on the end specifies the cycle of the step.  So you can change this section from:

      PWM 6, level1, 1
      PWM 7, level2, 1
      PWM 6, level1, 1
      PWM 7, level2, 1


to:

      PWM 6, level1, 2
      PWM 7, level2, 2


This keeps you from having to repeat the command.  That could be causing the issue you're seeing with the voltage drop, but I'm not sure.  One of the other members here may know more than I do.  For more details on the PWM command, look in the Basic Stamp Help File (Help menu > Basic Stamp Help > PBasic Language Reference > PWM)

I updated the code to make it a bit more readable.  Note that I named the pins at the top, which lets you change them around without having to dig through the code, and I also put in the initialization commands - these are important to have.

Also, you should do 255 - 0, not 255 - 1. 

Try this out and see if it makes a difference.  It looks pretty good on the Prop-1 Trainer.  I am using pins 0 and 1 instead of 6 and 7, because the Prop-1 Trainer doesn't have an LED on pin 7.  That's easy to change at the top if you need to.


' =========================================================================
'
'   File...... LED_Fader.BS1
'   Purpose...
'   Author.... gneirynck
'   E-mail....
'   Started...
'   Updated... 25 SEPT 2019
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  pin              = B2
SYMBOL  level1           = B3
SYMBOL  level2           = B4

SYMBOL  Led2             = 1
SYMBOL  Led1             = 0

' -----[ Initialization ]--------------------------------------------------

Reset:
  PINS = %00000000                              ' clear all
  DIRS = %00000011                              ' set outputs 0 and 1


' -----[ Program Code ]----------------------------------------------------

Main:

    HIGH  Led1        ' Turn on LED 1
    LOW   Led2        ' Turn off LED 2
    PAUSE 2000

    ' Cross-fade LED 1 to LED 2
    FOR level1 = 255 TO 0 STEP -1
      level2 = 255-level1
      PWM Led1, level1, 2
      PWM Led2, level2, 2
    NEXT

    ' Keep LED 2 on for 3 seconds
    HIGH  Led2
    PAUSE 3000

  GOTO Main



One thing I noticed is that you've got the fade only going one way, the final version is shown for three seconds, and then the lights reset back to the beginning.  Is that what you want?


gneirynck

Jeff - Thanks again for looking at this.  I was trying a lot of different things last night so I didn't get my code cleaned up, but agree with everything you said.  And yes, I only needed it to go one way.

I don't have the controller in front of me right now, but I was doing some research on the Internet and it looks like the PWM command only works for 0-5V.  So basically 'HIGH led1' would apply 12V to the LED, but 'PWM 1, 255, 1' would only apply 5V.  This is why LED 1 jumps down in brightness at the beginning and also why LED 2 jumps up in brightness once the fade is done. 

Do you or anyone know of a way to make this voltage use the full 12V range?

Jeff Haas

The docs show that Basic Stamp 1 (the microcontroller on the Prop-1) can control 0 - 5V via the TTL pins.  The terminal blocks on the Prop-1 are designed to turn power-hungry devices, like solenoids, on and off, so you can have them supply 12V.

However, usually LEDs don't need more than a few volts to run.  Even 5V is too much without resistors cutting down the voltage.  What LEDs are you using?  Do you have a link?  I've seen them where they come with resistors that let you use 12V, but the LEDs don't actually need that to work.

Jeff Haas

I also found this tutorial that might be useful for you:
https://www.youtube.com/watch?v=wCsDZK0tJvU