How can I get the FC-4 to fade a lamp up, then waiting a few seconds, the fading down. By triggering a pin on the prop1?
You didn't specify the fade up and down time so I used two seconds (8 milliseconds per step). Note that you have to add the fade timing to your between-fades delay. Please have a look at the FC-4 docs (http://www.efx-tek.com/downloads/fc-4_docs.pdf) for complete details.
' =========================================================================
'
' File...... Triggered_Fade.BS1
' Purpose...
' Author.... Jon Williams, EFX-TEK
' Copyright (c) 2009 EFX-TEK
' Some Rights Reserved
' -- see http://creativecommons.org/licenses/by/3.0/
' E-mail.... jwilliams@efx-tek.com
' Started...
' Updated... 14 APR 2009
'
' {$STAMP BS1}
' {$PBASIC 1.0}
'
' =========================================================================
' -----[ Program Description ]---------------------------------------------
' -----[ Revision History ]------------------------------------------------
' -----[ I/O Definitions ]-------------------------------------------------
SYMBOL Sio = 7 ' SETUP = UP; no ULN
SYMBOL Trigger = PIN6 ' SETUP = DN
' -----[ Constants ]-------------------------------------------------------
SYMBOL IsOn = 1 ' for active-high in/out
SYMBOL IsOff = 0
SYMBOL Yes = 1
SYMBOL No = 0
SYMBOL Baud = OT2400 ' B/R jumper removed
' -----[ Variables ]-------------------------------------------------------
SYMBOL timer = B2
' -----[ Initialization ]--------------------------------------------------
Reset:
PINS = %00000000 ' clear all
DIRS = %00000000 '
' -----[ Program Code ]----------------------------------------------------
Main:
timer = 0 ' reset timer
Check_Trigger:
PAUSE 5 ' loop pad
timer = timer + 5 * Trigger ' update timer
IF timer < 100 THEN Check_Trigger ' wait for 0.1 sec input
Fade_Up:
SEROUT Sio, Baud, ("!FC4", %00, "F", 1, 0, 255, 8)
Delay:
PAUSE 5000 ' ~2 (fade) + 3
Fade_Down:
SEROUT Sio, Baud, ("!FC4", %00, "F", 1, 255, 0, 8)
GOTO Main
' -----[ Subroutines ]-----------------------------------------------------
' -------------------------------------------------------------------------
' -----[ User Data ]-------------------------------------------------------
wonderful that works great! How can I add in a corss fade function. The same functionality as the other code but cross fading between 2 lights?
When you review the FC-4 docs (hint, hint...) this will make perfect sense.
' =========================================================================
'
' File...... Triggered_Fade.BS1
' Purpose...
' Author.... Jon Williams, EFX-TEK
' Copyright (c) 2009 EFX-TEK
' Some Rights Reserved
' -- see http://creativecommons.org/licenses/by/3.0/
' E-mail.... jwilliams@efx-tek.com
' Started...
' Updated... 14 APR 2009
'
' {$STAMP BS1}
' {$PBASIC 1.0}
'
' =========================================================================
' -----[ Program Description ]---------------------------------------------
' -----[ Revision History ]------------------------------------------------
' -----[ I/O Definitions ]-------------------------------------------------
SYMBOL Sio = 7 ' SETUP = UP; no ULN
SYMBOL Trigger = PIN6 ' SETUP = DN
' -----[ Constants ]-------------------------------------------------------
SYMBOL IsOn = 1 ' for active-high in/out
SYMBOL IsOff = 0
SYMBOL Yes = 1
SYMBOL No = 0
SYMBOL Baud = OT2400 ' B/R jumper removed
' -----[ Variables ]-------------------------------------------------------
SYMBOL timer = B2
' -----[ Initialization ]--------------------------------------------------
Reset:
PINS = %00000000 ' clear all
DIRS = %00000000 '
' -----[ Program Code ]----------------------------------------------------
Main:
SEROUT Sio, Baud, ("!FC4", %00, "D", %0001) ' Ch1 on
timer = 0 ' reset timer
Check_Trigger:
PAUSE 5 ' loop pad
timer = timer + 5 * Trigger ' update timer
IF timer < 100 THEN Check_Trigger ' wait for 0.1 sec input
Fade_1_to_2:
SEROUT Sio, Baud, ("!FC4", %00, "C", 0, 1, 2, 8)
Delay:
PAUSE 5000 ' ~2 (fade) + 3
Fade_2_to_1:
SEROUT Sio, Baud, ("!FC4", %00, "C", 0, 2, 1, 8)
GOTO Main
' -----[ Subroutines ]-----------------------------------------------------
' -------------------------------------------------------------------------
' -----[ User Data ]-------------------------------------------------------
Thanks Jon this did help in combination with the documentation. I still cant figure out how to adjust fade speed?
The fade speed is based on the number of steps (usually 256) and the time delay per step. For a full fade, from 0 to 255 or 255 to 0 (256 steps) and a step delay of 8 milliseconds your fade timing is 256 x 8 = 2048 (just a hair over 2 seconds). If you wanted to lengthen the fade to 3 seconds you would set the step delay to 12.
To calculate the step delay do this:
a) take fade (in milliseconds) and
b) divide by the number of steps in the fade (256 for full off-to-on or on-to-off)
c) round result to the nearest whole number
For example:
3000ms / 256 steps = 11.72 ms/step which would be rounded to 12
There are options with the C command that allow you to do partial fades so if you use those you'll have to adjust accordingly.
How would a fade on 4 seconds look in the serial command?
This command will fade channel 1 from off (0) to full on (255) in about 4 seconds:
SEROUT Sio, Baud, ("!FC4", %00, "F", 1, 0, 255, 16)
The fade step timing is calculated like this:
4000ms (4 seconds) / 256 (steps) = 15.62 --> round up to 16; actual fade time is 4.096 seconds.
Note: If you look at the examples in this thread you'll see that there for each second of a full fade you'll have four units in the step size, so 1 sec = 4, 2 secs = 8, 3 secs = 12, 4 secs = 16, etc.