From 1b86a08e5cbd48fcf28fe3cdc713fcb61c115637 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Thu, 23 Jul 2015 00:07:57 +0200 Subject: [PATCH] replace with fading with nice looking pattern --- test.rb | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/test.rb b/test.rb index a768708..d7c2530 100755 --- a/test.rb +++ b/test.rb @@ -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