Tissy
- 4th March 2005, 15:55
I have an RGB sequence which works fairly well, but very quickly. Is there a way of slowing down the routine. I have tried altering the PWM duty, but this just causes the LEDs to flicker. Also the Pause command produces the same flickering results.
I would like the transition of clours to be a lot slower.
This is part of a bigger routine, but i would like to get this part right.
Any ideas from anyone?
Many thanks,
Steve
TRISB = 0
Red VAR PORTB.1 ' All LEDs
Green VAR PORTB.2 ' Connected between
Blue VAR PORTB.3 ' RC pins and ground
rbgArray var byte[3] ' holds the rgb values in this case the led is rbg
x var byte
y var byte
adcVar var byte
rbg var byte ' which value we are changing in the rbg array
rainbowVal var byte ' the current value to produce rainbow
Delta var byte ' find the size of each section in the 6stage rainbow
Section var byte ' which section it is in
maxValue con 255 'the maximum input value for generating rainbow
delta = maxValue/6
y = 0
main:
for rainbowval = 0 to 255
gosub rbgrainbow
next
for rainbowval= 255 to 0 step - 1
gosub rbgrainbow
next
goto main
rbgrainbow:
for rbg = 0 to 2
section = ((rainbowval + ((rbg * 2)*delta))/ delta) // 6 ' this gives what section it is in
select case section
case 0
rbgarray[rbg] = (rainbowval // delta)*6 'this is how far it has gone in its section
case 1
rbgarray[rbg] = 255
case 2
rbgarray[rbg] = 255
case 3
rbgarray[rbg] = 255 - ((rainbowval //delta)*6)
case 4
rbgarray[rbg] = 0
case 5
rbgarray[rbg] = 0
case 6 'this one is for pics bad math
rbgarray[rbg] = 0
end select
next
gosub ledpwm
return
ledPWM:
For y = 0 to 2
Select Case y
Case 0
pwm red, rbgarray[y], 1
case 1
pwm blue, rbgarray[y], 1
case 2
pwm green, rbgarray[y], 1
end select
next
return
I would like the transition of clours to be a lot slower.
This is part of a bigger routine, but i would like to get this part right.
Any ideas from anyone?
Many thanks,
Steve
TRISB = 0
Red VAR PORTB.1 ' All LEDs
Green VAR PORTB.2 ' Connected between
Blue VAR PORTB.3 ' RC pins and ground
rbgArray var byte[3] ' holds the rgb values in this case the led is rbg
x var byte
y var byte
adcVar var byte
rbg var byte ' which value we are changing in the rbg array
rainbowVal var byte ' the current value to produce rainbow
Delta var byte ' find the size of each section in the 6stage rainbow
Section var byte ' which section it is in
maxValue con 255 'the maximum input value for generating rainbow
delta = maxValue/6
y = 0
main:
for rainbowval = 0 to 255
gosub rbgrainbow
next
for rainbowval= 255 to 0 step - 1
gosub rbgrainbow
next
goto main
rbgrainbow:
for rbg = 0 to 2
section = ((rainbowval + ((rbg * 2)*delta))/ delta) // 6 ' this gives what section it is in
select case section
case 0
rbgarray[rbg] = (rainbowval // delta)*6 'this is how far it has gone in its section
case 1
rbgarray[rbg] = 255
case 2
rbgarray[rbg] = 255
case 3
rbgarray[rbg] = 255 - ((rainbowval //delta)*6)
case 4
rbgarray[rbg] = 0
case 5
rbgarray[rbg] = 0
case 6 'this one is for pics bad math
rbgarray[rbg] = 0
end select
next
gosub ledpwm
return
ledPWM:
For y = 0 to 2
Select Case y
Case 0
pwm red, rbgarray[y], 1
case 1
pwm blue, rbgarray[y], 1
case 2
pwm green, rbgarray[y], 1
end select
next
return