replace with fading with nice looking pattern

This commit is contained in:
King Kévin 2015-07-23 00:07:57 +02:00
parent f3783caf43
commit 1b86a08e5c
1 changed files with 13 additions and 7 deletions

20
test.rb
View File

@ -27,13 +27,19 @@ NB_LEDS.times do |led|
sleep 0.1
end
puts "white fading"
white = 0
puts "nice colors"
phase = 0
msg = [0xff,0x00,0x00,3*NB_LEDS]+[0x00]*3*NB_LEDS
led_num = [10,9,8,7,6,5,4,3,2,1,0,11,12,13,14,15,16,17,18]+[29,28,27,26,25,24,23,22,21,20,19]+[41,42,43,44,45,46,47,48,40,39,38,37,36,35,34,33,32,31,30].reverse+[59,58,57,56,55,54,53,52,51,50,49].reverse
while true do
start = Time.now
screenlight.write ([0xff,0x00,0x00,3*NB_LEDS]+[white]*3*NB_LEDS).pack("C*") # set LED to red
screenlight.flush_output
NB_LEDS.times do |i|
led = led_num[i]
msg[led*3+4] = (Math::sin(phase*0.9+i*0.2)+1)*128
msg[led*3+5] = (Math::sin(phase+Math::PI/2+i*0.2)+1)*128
msg[led*3+6] = (Math::sin(phase*1.1+Math::PI+i*0.2)+1)*128
end
screenlight.write msg.pack("C*")
screenlight.flush_output
phase += 0.025
sleep 0.02
white = (white+1)%256
puts "set white #{white} in #{Time.now-start} s"
end