;======================= Driving an RGB LED with an EC1. ================================
; This assumes an RGB LED interfaced to analog (PWM) outputs 0, 1, and 2, which just
; happen to be the same pin numbers.
;[...]
;Define the outputs
aoRED           EQU     0
aoGRN           EQU     1
aoBLU           EQU     2
;[...]
;Define the 3 delays
tRedDelay       EQU     2
tGrnDelay       EQU     3
tBluDelay       EQU     4

;Let's just make 3 tasks that cycle the LEDS at slightly different rates. This will
;cover the whole gamut of the LED.
;[...]
                LaunchTask      tskRED
                LaunchTask      tskGRN
                LaunchTask      tskBLU
                RunTasksForever
;--------------------------------------------------------------------
;[...]               
tskRED:
RedGoUp:   ;In this loop we are incrementing the red channel. The actual value is held in the W register
                Pause           tRedDelay       ;Delay
                fLoadQ          0.01            ;The amount we will increment the output by
                fAdd                            ;Add the 0.01 to W
                fLoadQ          1               ;The maximum value we are allowed
                fGoIfWgtQ       RedGoDown       ;Jump if W > Q, meaning we hit the high limit
                fAnOut          aoRED           ;Output the new value
                GoTo            RedGoUp         ;Loop back and repeat

RedGoDown: ;In this loop we are decrementing the red channel. The actual value is held in the W register
                Pause           tRedDelay
                fLoadQ          -0.01           ;We will increment the output by a negative amount, i.e. decrement it
                fAdd                            ;Add the -0.01 to W
                fGoIfNeg        RedGoUp         ;Jump if W went negative
                fAnOut          aoRED           ;Output the new value
                GoTo            RedGoDown       ;Loop back and repeat                                                    
                                    
;--------------------------------------------------------------------
tskGRN:    
GrnGoUp:                                 
                Pause           tGrnDelay
                fLoadQ          0.01
                fAdd
                fLoadQ          1
                fGoIfWgtQ       GrnGoDown
                fAnOut          aoGRN
                GoTo            GrnGoUp
GrnGoDown:
                Pause           tGrnDelay
                fLoadQ          -0.01
                fAdd
                fGoIfNeg        GrnGoUp
                fAnOut          aoGRN
                GoTo            GrnGoDown                                                    
                                    
;--------------------------------------------------------------------
tskBLU:    
BluGoUp:                                 
                Pause           tBluDelay
                fLoadQ          0.01
                fAdd
                fLoadQ          1
                fGoIfWgtQ       BluGoDown
                fAnOut          aoBLU
                GoTo            BluGoUp
BluGoDown:
                Pause           tBluDelay
                fLoadQ          -0.01
                fAdd
                fGoIfNeg        BluGoUp
                fAnOut          aoBLU
                GoTo            BluGoDown
