November 24, 2024, 11:11:08 PM

News:

Be sure to checkout our Vixen interfaces in the Library forum -- if you want PC automation at near zero cost, EFX-TEK and Vixen is a great combination of tools.


Program code help for light

Started by Lindiur, October 26, 2011, 07:59:16 AM

Previous topic - Next topic

Lindiur

Hello all. Was hoping someone could write some code for me on a couple of LED lights. Seems simple, but well, I'm no guru. I have 2 LED's the first LED will start with it being on. Every 15 mins i need it to turn off and the 2nd LED to fade to on, pause then fade to off, and then back to the 1st LED.
So
LED 1 start by being on
15 minutes
LED 1 off
wait 3 seconds
LED 2 fade to brightness. 5 second fad
remain on for 5 seconds turn off for 3 seconds
turn back on for 5 seconds then a 5 second fade to off
remain off for 3 seconds then turn back on LED 1
no trigger just a 15 minute loop.

Thanks again for all the help in here.

bsnut

October 26, 2011, 01:54:30 PM #1 Last Edit: October 26, 2011, 02:42:28 PM by bsnut
From what I here that some minor details. I need to know what the voltage of these LEDs are they 12V or they 5V? Otherwise your program is easy to and I will try to bang this out for you, that's if another forum member doesn't do before me.
William Stefan
The Basic Stamp Nut

JackMan

QuoteLED 2 fade to brightness. 5 second fad
remain on for 5 seconds turn off for 3 seconds
turn back on for 5 seconds then a 5 second fade to off

Fading an LED on or off with a Prop-1 is a little complicated and requires a resistor/capacitor in the circuit. Fading and normal on/off of the same LED (which appears to be what you want to do) gets even more complex. You need to provide more details as Bill has mentioned and be as clear as you can about how you want it to work.

livinlowe

Quote from: JackMan on October 26, 2011, 02:10:38 PM
QuoteLED 2 fade to brightness. 5 second fad
remain on for 5 seconds turn off for 3 seconds
turn back on for 5 seconds then a 5 second fade to off

Fading an LED on or off with a Prop-1 is a little complicated and requires a resistor/capacitor in the circuit. Fading and normal on/off of the same LED (which appears to be what you want to do) gets even more complex. You need to provide more details as Bill has mentioned and be as clear as you can about how you want it to work.

If he is fading only one LED at a time, can't you use PWM?
Shawn
Scaring someone with a prop you built -- priceless!

JackMan

QuoteIf he is fading only one LED at a time, can't you use PWM?

I could very well be wrong but I don't think you can fade an LED using PWM alone without the proper resistor/capacitor added to the circuit. This would make switching that same LED on/off without any fade (which appears to be what Lindiur wants to do) a little complex.

Lindiur

Led 1 is a 3v 350mA. and Led 2 i'm not sure about. Its just the red led's for eyes you buy at radio shack.  Both Led's have a resistor on them. i have a box window with a pumpkin in it. the first led is orange and will light the pumpkin. then every 15 minutes it will shut off and the red led's will fade on....though if not possible they can just turn on....they will look like eyes in the window then they will go out and the pumpkin Led will turn back on.

Lindiur

So the first LED is a luxeon star and will not be fading....just lighting the pumpkin. The second is a radio shack LED and was hoping to fade it on and off.....but will live with just on if that is the case.
LED 1 on.......15 minutes
LED 1 off.....wait 3 seconds then turn on or fade to on (which ever works) LED2
If fading fade to brightness in 5 seconds and then hold for 5 seconds. turn off for 3 seconds the turn back on for 5 seconds
then fade to off in 5 seconds. wait 3 seconds and then turn back on LED1. and wait another 15 minutes to do again.
If not fading then turn LED2 on for 10 seconds. turn off for 3 and then back on for 10....off for 3 and back to LED1.
Thanks for all the help by the way.....Awesome place.

livinlowe

Quote from: JackMan on October 26, 2011, 08:48:49 PM
QuoteIf he is fading only one LED at a time, can't you use PWM?

I could very well be wrong but I don't think you can fade an LED using PWM alone without the proper resistor/capacitor added to the circuit. This would make switching that same LED on/off without any fade (which appears to be what Lindiur wants to do) a little complex.

I am also not sure, but I think the wick LED's have the capacitor to make the off transition longer to make it look more like a flame. But maybe Lindiur can experiment and see if regular PWM will work for the effect he is looking for!  :)
Shawn
Scaring someone with a prop you built -- priceless!

bsnut

October 27, 2011, 03:56:23 PM #8 Last Edit: October 27, 2011, 04:04:28 PM by bsnut
Here's your program for you without fading in it for right now, which should get you out of your hole you are in.

' =========================================================================
'
'   File......Pumpkin Lights Prop.bs1
'   Purpose...For lighting a pumpkin
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
'For non fading part
'LED 1 on.......15 minutes
'
'If not fading THEN turn LED2 on FOR 10 seconds. turn off FOR 3 AND THEN back
'on FOR 10....off FOR 3 AND back TO LED1
'
'NOTE: This Fading part is not used in this program code at this time.
'LED 1 off.....wait 3 seconds then turn on or fade to on (which ever works) LED2
'If fading fade to brightness in 5 seconds and then hold for 5 seconds.
'turn off FOR 3 seconds the turn back on FOR 5 seconds
'
'then fade TO off in 5 seconds. wait 3 seconds AND THEN turn back on LED1.
'AND wait another 15 minutes TO do again.
'

' -----[ Revision History ]------------------------------------------------


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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  LED1            = PIN0                  ' LED1 Pin
SYMBOL  LED2            = PIN1                  ' LED2 Pin


' -----[ Constants ]-------------------------------------------------------

SYMBOL  IsOn            = 1                     ' for active-high in/out
SYMBOL  IsOff           = 0

SYMBOL  Baud            = OT2400
SYMBOL  maxreps         = 2                     ' <- change max reps for lighting
                                                ' LED2 to meet your needs


' -----[ Variables ]-------------------------------------------------------

SYMBOL  ledreps         = B2
SYMBOL  timer           = W6


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

Reset:
  PINS = %00000000                              ' clear all outputs
  DIRS = %00111111                              ' make P0-P5 outputs


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

Main:
  timer = 0                                     ' reset timer
  LED1 = IsOn

  FOR timer = 0 TO 900                          ' run "timer" to 900secs = 15mins
    PAUSE 1000
  NEXT

Light_LED2:                                     ' controls lighting of LED2
  LED1 = IsOff
  LED2 = IsOn
  FOR ledreps = 0 TO maxreps                    ' control how many times LED2 is on
  PAUSE 10000
  LED1 = IsOff
  PAUSE 3000
  next

  GOTO Main


' -----[ Subroutines ]-----------------------------------------------------


' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------


What I suggest to you, is use a 12V LEDs over the ones that plan to use right now and here is reason why.  The LED at that you have sounds like they are rated way above the mA rating for the Basic Stamp 1 I/O pins. If you want to use these LEDs you will need to another resistor in series with the LED, which should protect the I/O pin and from killing the I/O. If you kill the I/O pin you will not be able to it any more, which is no  a good thing.

If you really want to do fading for this project. I would suggest you to get a 10k digitally potentiometer (part# AD5220) which can handle fading without any problems and it can be hooked up the I/O pin safely.

BTW, If you go to your local Radio Shack you should find a Book/Kit called "What's a Microcontroller" which has the 10k digitally potentiometer included in it. It also comes BS2 so you can learn programming an interfacing. Or, you can go online and get 10k the digitally potentiometer from Allied Electronics and download the "What's a Microcontroller" PDF form Parallax which shows you how to interface with the 10K digitally control potentiometer.
William Stefan
The Basic Stamp Nut

JonnyMac

Here's the program with fading on the Prop-1.  You must remember to execute the HIGH instruction right after a fade up to keep the LED on.  I created a constant called OneMinute so you can change this (e.g., to 1000) for testing -- 15 minutes is a long delay.

' =========================================================================
'
'   File......
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


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


SYMBOL  Led2            = 1
SYMBOL  Led1            = 0


' -----[ Constants ]-------------------------------------------------------

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  TrOn            = 1                     ' active-high trigger
SYMBOL  TrOff           = 0

SYMBOL  IsOn            = 1                     ' active-high I/O
SYMBOL  IsOff           = 0

SYMBOL  OneMinute       = 60000                 ' change to 1000 for testing


' -----[ Variables ]-------------------------------------------------------

SYMBOL  mins            = B2
SYMBOL  level           = B3


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

Power_Up:
  ' put code here that only happens at power-up/hard reset

Reset:
  PINS = %00000001                              ' start with LED #1
  DIRS = %00000011                              ' P1..P0 are outputs


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

Main:
  FOR mins = 1 TO 15
    PAUSE OneMinute
  NEXT

  PINS = %00000000                              ' both off
  PAUSE 3000                                    ' wait 3s

  FOR level = 0 TO 255                          ' fade up, ~5 secs
    PWM Led2, level, 4                          ' 255 x 5 x 4 = 5100ms
  NEXT

  HIGH Led2                                     ' required to keep on
  PAUSE 5000

  LOW Led2                                      ' off
  PAUSE 3000

  HIGH Led2
  PAUSE 5000

  FOR level = 255 TO 0 STEP -1                  ' fade down
    PWM Led2, level, 4
  NEXT

  GOTO Reset


' -----[ Subroutines ]-----------------------------------------------------


' -------------------------------------------------------------------------


' -------------------------------------------------------------------------


' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

QuoteI don't think you can fade an LED using PWM alone without the proper resistor/capacitor added to the circuit.

You can fade LEDs using PWM without any other components.  You just cannot hold any intermediate levels; the fade always has to end at full off or full on.
Jon McPhalen
EFX-TEK Hollywood Office

Lindiur

Thank you very much i will try this code and see. Once again thank you very much for all the info