Programik z projektu lampki na diodzie RGB:
http://tobe.nimio.info/led_mood_lamp.php
Jako, że autor nie ma nic przeciwko, pozwoliłem sobie pogrzebać we wsadzie.
Chciałem po pierwsze uzyskać biały kolor na starcie i udało się.
Nie mogę sobie natomiast poradzić z następującą rzeczą:
Przed zaświeceniem białego (R=160, G=240, B=255), chciałbym aby układ wykonał test barw podstawowych - na 1s włączył czerwoną, potem zieloną i na końcu niebieską diodę. Przerwy pomiędzy 0,5s.
Super byłoby jeśli po teście odpalenie białych byłoby stroboskopem - powiedzmy 10 mrugnięć w czasie 1s i przeszło do świecenia Wink
Czy ktoś może mi pomóc? Jestem laikiem w tym.
Dzięki z góry i pozdrawiam
Kod: Zaznacz cały
-- file : ikea_mood_lamp.jal
-- author : Toon Beerten
-- date : 21 August 2006
-- purpose : mood lamp program
-- contact : toon.beerten@gmail.com
-- website : http://tobe.nimio.info
--
-- Copyright (C) 2006 Toon Beerten
-- Free for non-commercial use
-- This software must be purchased if it is to be used in commercial endeavors,
-- but may be used free-of-charge for other purposes.
include 16f628_4
include jpic
include jlib
include jpwm3 -- custom pwm library
include jdelay
include jrtl -- jrtl = operators
include random3 -- random library
-- i use IntRC I/O, PWRT ON, BODEN ON, rest off
-- tick MCLR off when programming!!!!
var byte time = 1
var byte R = 255
var byte G = 1
var byte B = 1
var bit pause = false
option = option & 0x7f
disable_a_d_functions
-- disable_ad_inputs
pin_a0_direction = output
pin_a6_direction = input -- controls pause
pin_a2_direction = input -- random function
pin_a3_direction = output
pin_a4_direction = output
pin_a5_direction = output
pin_a1_direction = input -- controls transition
pin_a7_direction = input -- controls speed
pin_b0_direction = output
pin_b1_direction = output
pin_b2_direction = output
pin_b3_direction = output
pin_b4_direction = output
pin_b5_direction = output
pin_b6_direction = output
pin_b7_direction = output
-- randomize
randomize(34)
-- procedures
procedure speed is -- controls speed
if pin_a7 == high then
time = 50
else
time = 5
end if
end procedure
procedure flash is -- program to abruptly switch to another color
var byte RR
var byte GG
var byte BB
if pin_a2 == high then
RR = random_byte
GG = random_byte
BB = random_byte
else
RR = 255
GG = 1
BB = 1
end if
For 254 loop
speed
if pin_a1 == low then
return
end if
PWM_OUT(RR,GG,BB, time)
end loop
while pin_a6 == high loop
PWM_OUT(RR,GG,BB, time)
end loop
if pin_a2 == high then
RR = random_byte
GG = random_byte
BB = random_byte
else
RR = 255
GG = 255
BB = 1
end if
For 254 loop
speed
if pin_a1 == low then
return
end if
PWM_OUT(RR,GG,BB, time)
end loop
while pin_a6 == high loop
PWM_OUT(RR,GG,BB, time)
end loop
if pin_a2 == high then
RR = random_byte
GG = random_byte
BB = random_byte
else
RR = 1
GG = 255
BB = 1
end if
For 254 loop
speed
if pin_a1 == low then
return
end if
PWM_OUT(RR,GG,BB, time)
end loop
while pin_a6 == high loop
PWM_OUT(RR,GG,BB, time)
end loop
if pin_a2 == high then
RR = random_byte
GG = random_byte
BB = random_byte
else
RR = 1
GG = 255
BB = 255
end if
For 254 loop
speed
if pin_a1 == low then
return
end if
PWM_OUT(RR,GG,BB, time)
end loop
while pin_a6 == high loop
PWM_OUT(RR,GG,BB, time)
end loop
if pin_a2 == high then
RR = random_byte
GG = random_byte
BB = random_byte
else
RR = 1
GG = 1
BB = 255
end if
For 254 loop
speed
if pin_a1 == low then
return
end if
PWM_OUT(RR,GG,BB, time)
end loop
while pin_a6 == high loop
PWM_OUT(RR,GG,BB, time)
end loop
if pin_a2 == high then
RR = random_byte
GG = random_byte
BB = random_byte
else
RR = 255
GG = 1
BB = 255
end if
For 254 loop
speed
if pin_a1 == low then
return
end if
PWM_OUT(RR,GG,BB, time)
end loop
while pin_a6 == high loop
PWM_OUT(RR,GG,BB, time)
end loop
if pin_a2 == high then
RR = random_byte
GG = random_byte
BB = random_byte
else
RR = 255
GG = 1
BB = 1
end if
end procedure
procedure fade(byte in Rnew, byte in Gnew, byte in Bnew) is
-- fade from 1 colour to another
-- passing 0 means stay the same
var byte counter = 0
if Rnew != 0 then
if Rnew > R then
counter = Rnew - R
elsif Rnew < R then
counter = R - Rnew
end if
For counter loop -- (R,G,B)
speed
PWM_OUT(R,G,B, time)
if Rnew > R then
R = R + 1
else
R = R - 1
end if
if pin_a1 == high then -- other mode
flash
end if
while pin_a6 == high loop -- pause
PWM_OUT(R,G,B, time)
end loop
end loop -- (Rnew,Gnew,Bnew)
end if
if Gnew != 0 then
if Gnew > G then
counter = Gnew - G
elsif Gnew < G then
counter = G - Gnew
end if
For counter loop -- (R,G,B)
speed
PWM_OUT(R,G,B, time)
if Gnew > G then
G = G + 1
else
G = G - 1
end if
if pin_a1 == high then -- other mode
flash
end if
while pin_a6 == high loop -- pause
PWM_OUT(R,G,B, time)
end loop
end loop -- (Rnew,Gnew,Bnew)
end if
if Bnew != 0 then
if Bnew > B then
counter = Bnew - B
elsif Bnew < B then
counter = B - Bnew
end if
For counter loop -- (R,G,B)
speed
PWM_OUT(R,G,B, time)
if Bnew > B then
B = B + 1
else
B = B - 1
end if
if pin_a1 == high then -- other mode
flash
end if
while pin_a6 == high loop -- pause
PWM_OUT(R,G,B, time)
end loop
end loop -- (Rnew,Gnew,Bnew)
end if
end procedure
-- main loop
forever loop
-- we start at R = 255, G = 1, B = 1
if pin_a2 == high then
fade(random_byte,0,0)
fade(0,random_byte,0)
fade(0,0,random_byte)
else
R = 255
G = 1
B = 1
fade(0,255,0)
fade(1,0,0)
fade(0,0,255)
fade(0,1,0)
fade(255,0,0)
fade(0,0,1)
end if
end loop
Biały uzyskałem dodając na początku programu:
Kod: Zaznacz cały
if pin_a2 == high then
RR = random_byte
GG = random_byte
BB = random_byte
else
RR = 160
GG = 240
BB = 255
end if
For 254 loop
speed
if pin_a1 == low then
return
end if
PWM_OUT(RR,GG,BB, time)
end loop
while pin_a6 == high loop
PWM_OUT(RR,GG,BB, time)
end loop
[ Dodano: 05-05-2007, 11:44 ]
Naprawdę nikt nie jest w stanie nic podpowiedzieć?