Class: Denko::LED::RGB

Inherits:
Object
  • Object
show all
Includes:
Behaviors::MultiPin
Defined in:
lib/denko/led/rgb.rb

Constant Summary collapse

COLORS =

Format: [R, G, B]

{
  red:     [100, 000, 000],
  green:   [000, 100, 000],
  blue:    [000, 000, 100],
  cyan:    [000, 100, 100],
  yellow:  [100, 100, 000],
  magenta: [100, 000, 100],
  white:   [100, 100, 100],
  off:     [000, 000, 000]
}

Constants included from Behaviors::Lifecycle

Behaviors::Lifecycle::CALLBACK_METHODS

Instance Attribute Summary

Attributes included from Behaviors::MultiPin

#pin, #pins, #proxies

Attributes included from Behaviors::Component

#board, #params

Attributes included from Behaviors::State

#state

Instance Method Summary collapse

Methods included from Behaviors::MultiPin

#convert_pins, #proxy_pin, #proxy_states, #require_pin, #require_pins

Methods included from Behaviors::Lifecycle

included

Methods included from Behaviors::Component

#initialize, #micro_delay

Methods included from Behaviors::State

#update_state

Instance Method Details

#color=(color) ⇒ Object



36
37
38
39
# File 'lib/denko/led/rgb.rb', line 36

def color=(color)
  color = color.to_sym
  write(*COLORS[color]) if COLORS.include? color
end

#initialize_pins(options = {}) ⇒ Object



6
7
8
9
10
# File 'lib/denko/led/rgb.rb', line 6

def initialize_pins(options={})
  proxy_pin :red,   LED::Base
  proxy_pin :green, LED::Base
  proxy_pin :blue,  LED::Base
end

#write(r, g, b) ⇒ Object



24
25
26
27
28
# File 'lib/denko/led/rgb.rb', line 24

def write(r, g, b)
  red.duty   = r
  green.duty = g
  blue.duty  = b
end

#write_8_bit(r, g, b) ⇒ Object



30
31
32
33
34
# File 'lib/denko/led/rgb.rb', line 30

def write_8_bit(r, g, b)
  red.duty   = ((r / 255.0) * 100).round
  green.duty = ((g / 255.0) * 100).round
  blue.duty  = ((b / 255.0) * 100).round
end