Module: WS2801::Effects
- Defined in:
- lib/ws2801/effects.rb
Overview
Controller for: RGB Pixel with WS2801 Chip (Effects) build for Diffused Digital RGB LED Pixels from Adafruits on Raspberry Pi but should work on any device and the same led chip © 2013 Roman Pramberger ([email protected])
WS2801 user-space driver (effects)
Class Method Summary collapse
-
.pulse(options = {}) ⇒ Object
keep: (Boolean) if pixels get blacked out [default: true].
-
.stroboscope(options = {}) ⇒ Object
Stroboscope effect.
Class Method Details
.pulse(options = {}) ⇒ Object
keep: (Boolean) if pixels get blacked out [default: true]
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/ws2801/effects.rb', line 73 def self.pulse = {} [:pixel] = (0..(WS2801.length-1)).to_a if [:pixel].nil? or [:pixel] == :all [:pixel] = [[:pixel]] if [:pixel].is_a? Numeric [:r] = 0 if [:r].nil? [:g] = 0 if [:g].nil? [:b] = 0 if [:b].nil? [:direction] = :start if [:direction].nil? [:timeout] = 0.1 if [:timeout].to_f == 0.0 [:keep] = true if [:keep].nil? WS2801.generate if ![:keep] if [:direction] == :start WS2801.length.times do |i| WS2801.generate if ![:keep] WS2801.set({ :r => [:r], :g => [:g], :b => [:b], :pixel => i }) sleep([:timeout]) end elsif [:direction] == :end WS2801.length.times do |i| WS2801.generate if ![:keep] WS2801.set({ :r => [:r], :g => [:g], :b => [:b], :pixel => WS2801.length-i }) sleep([:timeout]) end elsif [:direction] == :inner first = WS2801.length/2.0 if first % 1 != 0 first = first.to_i + 1 end WS2801.generate if ![:keep] ((WS2801.length/2)+1).times do |i| WS2801.generate if ![:keep] WS2801.set({ :pixel => [first-i, first+i], :r => [:r], :g => [:g], :b => [:b] }) sleep([:timeout]) end elsif [:direction] == :outer WS2801.generate if ![:keep] ((WS2801.length/2)+1).times do |i| WS2801.generate if ![:keep] WS2801.set({ :pixel => [0+i, WS2801.length-i], :r => [:r], :g => [:g], :b => [:b] }) sleep([:timeout]) end end end |
.stroboscope(options = {}) ⇒ Object
Stroboscope effect
Example:
>> WS2801E.stroboscope({ :timeout => 0.25, :times => 22, :r => 255 })
>> WS2801E.stroboscope({ :b => 255, :g => 255 })
Arguments (or nil):
pixel: (Number-Array|Integer|:all)
r: (Integer) 0-255 red
g: (Integer) 0-255 green
b: (Integer) 0-255 blue
timeout: (Float)
times: (Integer)
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ws2801/effects.rb', line 26 def self.stroboscope = {} [:pixel] = (0..(WS2801.length-1)).to_a if [:pixel].nil? or [:pixel] == :all [:pixel] = [[:pixel]] if [:pixel].is_a? Numeric [:r] = 0 if [:r].nil? [:g] = 0 if [:g].nil? [:b] = 0 if [:b].nil? [:times] = [:times].to_i if ![:times].is_a? Numeric [:times] = 40 if [:times] == 0 [:timeout] = [:timeout].to_f [:timeout] = 0.03 if [:timeout] == 0.0 breakme = 0 [:times].times do |c| if c % 2 == 0 r = 0 g = 0 b = 0 else r = [:r] g = [:g] b = [:b] end WS2801.set({ :pixel => [:pixel], :r => r, :g => g, :b => b }) sleep( [:timeout] ) end end |