Class: Denko::LED::WS2812
Constant Summary
Behaviors::Lifecycle::CALLBACK_METHODS
Instance Attribute Summary collapse
#mode, #pin
#board, #params
#state
Instance Method Summary
collapse
included
#convert_pins, #initialize_pins
#initialize, #micro_delay
#update_state
Instance Attribute Details
#bpp ⇒ Object
11
12
13
|
# File 'lib/denko/led/ws2812.rb', line 11
def bpp
@bpp ||= params[:bpp] || 3
end
|
#length ⇒ Object
7
8
9
|
# File 'lib/denko/led/ws2812.rb', line 7
def length
@length ||= params[:length] || 1
end
|
Instance Method Details
#[]=(index, array) ⇒ Object
21
22
23
24
25
26
|
# File 'lib/denko/led/ws2812.rb', line 21
def []=(index, array)
buffer[index*bpp] = array[1]
buffer[index*bpp+1] = array[0]
buffer[index*bpp+2] = array[2]
end
|
#all_on ⇒ Object
32
33
34
35
|
# File 'lib/denko/led/ws2812.rb', line 32
def all_on
buffer.map! { 255 }
show
end
|
#buffer ⇒ Object
28
29
30
|
# File 'lib/denko/led/ws2812.rb', line 28
def buffer
@buffer ||= Array.new(length * bpp) { 0 }
end
|
#clear ⇒ Object
42
43
44
|
# File 'lib/denko/led/ws2812.rb', line 42
def clear
buffer.map! { 0 }
end
|
#off ⇒ Object
37
38
39
40
|
# File 'lib/denko/led/ws2812.rb', line 37
def off
clear
show
end
|
#show ⇒ Object
46
47
48
|
# File 'lib/denko/led/ws2812.rb', line 46
def show
board.show_ws2812(self.pin, self.buffer)
end
|