Class: Denko::LED::WS2812

Inherits:
Object
  • Object
show all
Includes:
Behaviors::Lifecycle, Behaviors::SinglePin
Defined in:
lib/denko/led/ws2812.rb

Constant Summary

Constants included from Behaviors::Lifecycle

Behaviors::Lifecycle::CALLBACK_METHODS

Instance Attribute Summary collapse

Attributes included from Behaviors::SinglePin

#mode, #pin

Attributes included from Behaviors::Component

#board, #params

Attributes included from Behaviors::State

#state

Instance Method Summary collapse

Methods included from Behaviors::Lifecycle

included

Methods included from Behaviors::SinglePin

#convert_pins, #initialize_pins

Methods included from Behaviors::Component

#initialize, #micro_delay

Methods included from Behaviors::State

#update_state

Instance Attribute Details

#bppObject



11
12
13
# File 'lib/denko/led/ws2812.rb', line 11

def bpp
  @bpp ||= params[:bpp] || 3
end

#lengthObject



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)
  # Just do GRB order for now.
  buffer[index*bpp]   = array[1]
  buffer[index*bpp+1] = array[0]
  buffer[index*bpp+2] = array[2]
end

#all_onObject



32
33
34
35
# File 'lib/denko/led/ws2812.rb', line 32

def all_on
  buffer.map! { 255 } # should scale with brightness
  show
end

#bufferObject



28
29
30
# File 'lib/denko/led/ws2812.rb', line 28

def buffer
  @buffer ||= Array.new(length * bpp) { 0 }
end

#clearObject



42
43
44
# File 'lib/denko/led/ws2812.rb', line 42

def clear
  buffer.map! { 0 }
end

#offObject



37
38
39
40
# File 'lib/denko/led/ws2812.rb', line 37

def off
  clear
  show
end

#showObject



46
47
48
# File 'lib/denko/led/ws2812.rb', line 46

def show
  board.show_ws2812(self.pin, self.buffer)
end