I want to share as a beginner with a very nice project which I made as a gift for a my friend. The project is simple, but for me take a lot of time to create. I hope that maybe someone will want to repeat, or give as an idea for another project. I think people need more published examples of their projects, to other people take good ideas and solutions.
I am delighted that there are such enthusiasts as Anobium, kent14, Thomass Henry and some more guys, which help and take care of the GCB existence and development.
chip 12f683,4
config osc=int
define sw gpio.5
define red gpio.0
define green gpio.1
define blue gpio.2
dir red out
dir green out
dir blue out
dir sw in
cnt1=0
cnt2=0
cnt3=0
now=0
prev=0
time=0
test=0
rered=0
regreen=0
reblue=0
brightred=0
brightgreen=0
brightblue=0
cycle:
if sw=off then ' if press and hold switch over ~2sec then led's switch off
time++
else
time=0
end if
if time=100 then test=1
now=!sw
if now>prev then test++ ' with each button press is changing case
prev=now
if test=19 then
test=0
now=0
prev=0
end if
select case test
case 1
set red off
set green off
set blue off
case 2
call softpwm
brightred=255
brightgreen=255
brightblue=255
case 3
call softpwm
brightred=150
brightgreen=150
brightblue=150
case 4
call softpwm
brightred=50
brightgreen=50
brightblue=50
case 5
call softpwm
brightred=15
brightgreen=15
brightblue=15
case 6
for cnt1 = 255 to 0
if sw=off & cnt1<240 then
test=7 'goto case 7
cnt1=0
cnt2=0
cnt3=0
end if
for speed1=0 to 3 '' speed control
call softpwm
brightred=cnt1
brightgreen=255-cnt1
brightblue=0
next speed1
next cnt2
for cnt2=255 to 0
if sw=off & cnt2<240 then
test=7
cnt1=0
cnt2=0
cnt3=0
end if
for speed2=0 to 3
call softpwm
brightred=0
brightgreen=cnt2
brightblue=255-cnt2
next speed2
next cnt3
for cnt3= 255 to 0
if sw=off & cnt3<240 then
test=7
cnt1=0
cnt2=0
cnt3=0
end if
for speed3=0 to 3
call softpwm
brightblue=cnt3
brightred=255-cnt3
brightgreen=0
next speed3
next cnt1
case 7 ''red
call softpwm
brightred=255
brightgreen=0
brightblue=0
case 8 '' orange
call softpwm
brightred=255
brightgreen=35
brightblue=0
case 9 ''yellow
call softpwm
brightred=255
brightgreen=85
brightblue=0
case 10 ''green
call softpwm
brightred=81
brightgreen=197
brightblue=0
case 11 '' lime
call softpwm
brightred=0
brightgreen=255
brightblue=0
case 12 ''turquise
call softpwm
brightred=0
brightgreen=255
brightblue=255
case 13 ''cyan
call softpwm
brightred=0
brightgreen=198
brightblue=255
case 14 '' sky
call softpwm
brightred=0
brightgreen=85
brightblue=255
case 15 '' blue
call softpwm
brightred=0
brightgreen=0
brightblue=255
case 16 '' purple
call softpwm
brightred=255
brightgreen=0
brightblue=255
case 17 '' magneta
call softpwm
brightred=255
brightgreen=0
brightblue=55 ''255
case 18 '' pink
call softpwm
brightred=255
brightgreen=0
brightblue=32''127
end select
goto cycle
sub SoftPWM 'PWM generator
For duty = 1 to 255
If brightred > duty then
red = 1
else
red = 0
end if
If brightgreen > duty then
green = 1
else
green = 0
end if
If brightblue > duty then
blue = 1
else
blue = 0
end if
Next
end sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hallo!
I want to share as a beginner with a very nice project which I made as a gift for a my friend. The project is simple, but for me take a lot of time to create. I hope that maybe someone will want to repeat, or give as an idea for another project. I think people need more published examples of their projects, to other people take good ideas and solutions.
I am delighted that there are such enthusiasts as Anobium, kent14, Thomass Henry and some more guys, which help and take care of the GCB existence and development.
chip 12f683,4
config osc=int
define sw gpio.5
define red gpio.0
define green gpio.1
define blue gpio.2
dir red out
dir green out
dir blue out
dir sw in
cnt1=0
cnt2=0
cnt3=0
now=0
prev=0
time=0
test=0
rered=0
regreen=0
reblue=0
brightred=0
brightgreen=0
brightblue=0
cycle:
if sw=off then ' if press and hold switch over ~2sec then led's switch off
time++
else
time=0
end if
if time=100 then test=1
now=!sw
if now>prev then test++ ' with each button press is changing case
prev=now
if test=19 then
test=0
now=0
prev=0
end if
select case test
case 1
set red off
set green off
set blue off
case 2
call softpwm
brightred=255
brightgreen=255
brightblue=255
case 3
call softpwm
brightred=150
brightgreen=150
brightblue=150
case 4
call softpwm
brightred=50
brightgreen=50
brightblue=50
case 5
call softpwm
brightred=15
brightgreen=15
brightblue=15
case 6
for cnt1 = 255 to 0
if sw=off & cnt1<240 then
test=7 'goto case 7
cnt1=0
cnt2=0
cnt3=0
end if
for speed1=0 to 3 '' speed control
call softpwm
brightred=cnt1
brightgreen=255-cnt1
brightblue=0
next speed1
next cnt2
for cnt2=255 to 0
if sw=off & cnt2<240 then
test=7
cnt1=0
cnt2=0
cnt3=0
end if
for speed2=0 to 3
call softpwm
brightred=0
brightgreen=cnt2
brightblue=255-cnt2
next speed2
next cnt3
for cnt3= 255 to 0
if sw=off & cnt3<240 then
test=7
cnt1=0
cnt2=0
cnt3=0
end if
for speed3=0 to 3
call softpwm
brightblue=cnt3
brightred=255-cnt3
brightgreen=0
next speed3
next cnt1
case 7 ''red
call softpwm
brightred=255
brightgreen=0
brightblue=0
case 8 '' orange
call softpwm
brightred=255
brightgreen=35
brightblue=0
case 9 ''yellow
call softpwm
brightred=255
brightgreen=85
brightblue=0
case 10 ''green
call softpwm
brightred=81
brightgreen=197
brightblue=0
case 11 '' lime
call softpwm
brightred=0
brightgreen=255
brightblue=0
case 12 ''turquise
call softpwm
brightred=0
brightgreen=255
brightblue=255
case 13 ''cyan
call softpwm
brightred=0
brightgreen=198
brightblue=255
case 14 '' sky
call softpwm
brightred=0
brightgreen=85
brightblue=255
case 15 '' blue
call softpwm
brightred=0
brightgreen=0
brightblue=255
case 16 '' purple
call softpwm
brightred=255
brightgreen=0
brightblue=255
case 17 '' magneta
call softpwm
brightred=255
brightgreen=0
brightblue=55 ''255
case 18 '' pink
call softpwm
brightred=255
brightgreen=0
brightblue=32''127
end select
goto cycle
sub SoftPWM 'PWM generator
For duty = 1 to 255
If brightred > duty then
red = 1
else
red = 0
end if
If brightgreen > duty then
green = 1
else
green = 0
end if
If brightblue > duty then
blue = 1
else
blue = 0
end if
Next
end sub