Class: Denko::LED::WS2812
Instance Attribute Summary collapse
#mode, #pin
#board
Instance Method Summary
collapse
#initialize, #micro_delay
#initialize, #state
Instance Attribute Details
#bpp ⇒ Object
Returns the value of attribute bpp.
6
7
8
|
# File 'lib/denko/led/ws2812.rb', line 6
def bpp
@bpp
end
|
#length ⇒ Object
Returns the value of attribute length.
6
7
8
|
# File 'lib/denko/led/ws2812.rb', line 6
def length
@length
end
|
Instance Method Details
#[]=(index, array) ⇒ Object
18
19
20
21
22
23
|
# File 'lib/denko/led/ws2812.rb', line 18
def []=(index, array)
buffer[index*bpp] = array[1]
buffer[index*bpp+1] = array[0]
buffer[index*bpp+2] = array[2]
end
|
#after_initialize(options = {}) ⇒ Object
8
9
10
11
12
13
14
15
16
|
# File 'lib/denko/led/ws2812.rb', line 8
def after_initialize(options={})
super(options)
raise ArgumentError, "no length given for WS2812 array" unless options[:length]
@length = options[:length]
@bpp = 3
off
end
|
#all_on ⇒ Object
29
30
31
32
|
# File 'lib/denko/led/ws2812.rb', line 29
def all_on
buffer.map! { 255 } show
end
|
#buffer ⇒ Object
25
26
27
|
# File 'lib/denko/led/ws2812.rb', line 25
def buffer
@buffer ||= Array.new(length * bpp) { 0 }
end
|
#clear ⇒ Object
39
40
41
|
# File 'lib/denko/led/ws2812.rb', line 39
def clear
buffer.map! { 0 }
end
|
#off ⇒ Object
34
35
36
37
|
# File 'lib/denko/led/ws2812.rb', line 34
def off
clear
show
end
|
#show ⇒ Object
43
44
45
|
# File 'lib/denko/led/ws2812.rb', line 43
def show
board.show_ws2812(self.pin, self.buffer)
end
|