
; LED_fade.EZ
; Foxonix / Metre Ideas and Design
; www.foxonix.com

; Program: Will Sakran
; Created: 02.26.14
; Public - Modify and share this program as you wish.

; Program description
;	Fade an LED in and out

; Hardware OUTPUTS
; 	LED connected to pin P3.3


; Set the device name
[device]
SNC21030


; Specify the number of pins to be used as inputs.
; At lease one input must be defined even if it is not used.
[key]
direct=1


; Define the various input states for the program.
; This describes which pins will have buttons, switches, or
; other inputs attached to them, and defines when those
; inputs will be active and inactive. At least one input
; must be defined even if it is not used.
[input_states]
; Port.Pin		P1.0
locked_out:		x


; Define the routines (paths) that the program will use.
; The init path is always called first on power up and reset.
[paths]
init:
	& X0=0				; initialize 8-bit register X0 to 0
	& pwmio_en4			; enable PWM for pin P3.3
	& fade_in			; jump to the fade_in: label

fade_in:
	& pwmio4=X0			; set PWM on pin P3.3 to the value in X0
	& delay(0.010)			; delay to control fade in time
	& X0?255:fade_out		; if max PWM is reached (255), jump to fade_out: label
	& X0=X0+1			; if not, increment PWM
	& fade_in			; continue fading in

fade_out:
	& pwmio4=X0			; set PWM on pin P3.3 to the value in X0
	& delay(0.010)			; delay to control fade in time
	& X0?0:fade_in			; if min PWM is reached (0), jump to fade_in: label
	& X0=X0-1			; if not, decrement PWM
	& fade_out			; continue fading out

