I'm not an electronics person but have some programming knowledge, very new to picaxe. I'm trying to control as many LEDs as I can on a 14M2 to make the LEDs glow brighter and dimmer independent. Currently I have a program which is an endless loop which uses several variables monitor the brightness and also variables to indicate if the LED is getting brighter or dimmer. IF statements check the limits and change brightness/dimness direction. Then a series of PWM commands to control the LEDs level of brightness. The problem I have is that on each pass of the PWM commands, the LEDs flash which prevents the smooth brightness change that I'm looking. Is there a way to prevent this flashing, perhaps with some kind of concurrent subroutines? I'm not sure if I should be using PWMDUTY, PWMOUT or whatever. Also, I've played unsuccessful with the simulator to display the values of the variables as the program executes.
One of the versions of the code I've been tinkering with is listed below, thanks in advance.
One of the versions of the code I've been tinkering with is listed below, thanks in advance.
Code:
w1=50
w2=100
w4=150
w6=200
w7=1
w8=1
w10=1
w12=1
PWMOUT B.2,w1,1
PWMOUT B.4,w2,1
PWMOUT C.0,w4,1
PWMOUT C.2,w6,1
main:
IF w7=1 THEN
INC w1
ELSE
DEC w1
ENDIF
IF w8=1 THEN
INC w2
ELSE
DEC w2
ENDIF
IF w10=1 THEN
INC w4
ELSE
DEC w4
ENDIF
IF w12=1 THEN
INC w6
ELSE
DEC w6
ENDIF
IF w1 >= 255 THEN
w7 = 0
ELSEIF w1 <= 15 THEN
w7 = 1
ENDIF
IF w2 >= 255 THEN
w8 = 0
ELSEIF w2 <= 15 THEN
w8 = 1
ENDIF
IF w4 >= 255 THEN
w10 = 0
ELSEIF w4 <= 15 THEN
w10 = 1
ENDIF
IF w6 >= 255 THEN
w12 = 0
ELSEIF w6 <= 15 THEN
w12 = 1
ENDIF
PWMDUTY B.2,w1
PWMDUTY B.4,w2
PWMDUTY C.0,w4
PWMDUTY C.2,w6
GOTO MAIN