I have found this piece of code, which i think may do what i need. How do i change the outputs so that it fades the LEDs on RC0 - RC2 and not RB5 through to RB7?
Is there anything else that'll need modifiying if i am using a PIC16F876.
Many thanks.
Code:
' PicBasic Pro program for fading RGB LED's.
' Note that this program uses the
' Basic Stamp-equivalent pin numbers, 5 through 7.
' These correspond to pins RB5 through RB7.
include "modedefs.bas"
DEFINE OSC 4
DEFINE ADC_BITS 8
DEFINE ADC_CLOCK 3
DEFINE SAMPLEUS 50
TRISB = %00000000
TRISA = %11111111
TRISD = %00000000
ADCON1 = %00000010
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
for x = 5 to 7
high x
pause 1000
low x
next
main:
adcin 0, rainbowval
'serout2 portc.6, 16468, ["rainbow val: ", dec rainbowval, 13, 10]
gosub rbgrainbow
goto main
rbgrainbow:
for rbg = 0 to 2
section = ((rainbowval + ((rbg * 2)*delta))/ delta) // 6 ' this gives what section it is in
'serout2 portc.6, 16468, ["rbg: ", dec rbg, 13,10,"section: ", dec section, 13, 10]
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
pwm 5 + y, rbgarray[y], 1
'serout2 portc.6, 16468, ["color",dec y, ": ", dec rbgarray[y], 13, 10]
next
return
Bookmarks