November 23, 2024, 04:35:34 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.


Fading running lights

Started by imagineerdan, March 09, 2009, 05:44:38 PM

Previous topic - Next topic

imagineerdan

I have been trying create a program that fades LEDs in secsession/ This is what I have been starting with, which has given me no luck. How can this be altered to work :)


'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================

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

SYMBOL  pinNum          = B2
SYMBOL  level           = B3


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

Reset:

DIRS = %11111111                              ' P0 - P7 are outs


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

Main:
  FOR pinNum = 0 TO 7                           ' loop through outputs
    FOR level = 0 TO 255 STEP -8                ' bright to dark
      PWM pinNum, level, 2
    NEXT
  NEXT
  GOTO Main


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


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


JonnyMac

Give this version a try.

Two details: 1) PWM leaves the pin in an input state so you need to refresh the DIRS register and, 2) When counting backward with FOR-NEXT you have to specify the larger number first.

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


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


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


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

SYMBOL  Lights          = PINS


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

SYMBOL  AllOn           = %11111111


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

SYMBOL  pinNum          = B2
SYMBOL  level           = B3


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

Reset:
  DIRS = %11111111                              ' set outputs
  Lights = AllOn


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

Main:
  PAUSE 100
  FOR pinNum = 0 TO 7
    FOR level = 255 TO 0 STEP -8
      PWM pinNum, level, 1
    NEXT
  NEXT
  GOTO Reset


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


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

imagineerdan

That works great! Now for my next effect I need to make three out puts flicker in secession, one after the other. I guess it would almost be a hybrid of the candle flicker code and this one? How would that look? Thanks again !

JonnyMac

Please post that request in a new thread -- threads are by topic, not person; makes them easier to search.  And, as ever, provide as much detail (description) as possible.  Thanks.
Jon McPhalen
EFX-TEK Hollywood Office