Class: LED::RGB

Inherits:
DigitalEffector show all
Defined in:
lib/led_rgb.rb

Instance Method Summary collapse

Methods inherited from DigitalEffector

off, #off?, on, #on?

Methods inherited from Effector

#model_name, #name

Constructor Details

#initialize(red = 17, green = 27, blue = 22) ⇒ RGB

Returns a new instance of RGB.



9
10
11
12
13
14
# File 'lib/led_rgb.rb', line 9

def initialize(red = 17, green = 27, blue = 22)
  super({:red => red, :green => green, :blue => blue}, :low)
  @red   = red
  @green = green
  @blue  = blue
end

Instance Method Details

#all_offObject



81
82
83
84
85
# File 'lib/led_rgb.rb', line 81

def all_off
  red_off
  green_off
  blue_off
end


88
89
90
91
92
93
94
95
96
97
98
# File 'lib/led_rgb.rb', line 88

def blink(list = :all, repeat=3, switched_on=0.25, switched_off=0.5)
  colors = (list == :all) ? [:red, :green, :blue] : (list.class == Array ? list : [list])
  repeat.times do |n|
    colors.each do |color|
      on color
      sleep switched_on
      off color
      sleep switched_off
    end
  end
end

#blue_offObject



36
37
38
# File 'lib/led_rgb.rb', line 36

def blue_off
  DigitalEffector.off @blue
end

#blue_onObject



32
33
34
# File 'lib/led_rgb.rb', line 32

def blue_on
  DigitalEffector.on @blue
end

#green_offObject



28
29
30
# File 'lib/led_rgb.rb', line 28

def green_off
  DigitalEffector.off @green
end

#green_onObject



24
25
26
# File 'lib/led_rgb.rb', line 24

def green_on
  DigitalEffector.on @green
end

#off(color = :all) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/led_rgb.rb', line 59

def off(color=:all)
  color = :aoi if color == :aqua
  case color
  when :red
    red_off
  when :green
    green_off
  when :blue
    blue_off
  when :yellow
    red_off
    green_off
  when :aoi
    blue_off
    green_off
  when :all
    all_off
  else
    all_off
  end
end

#on(color) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/led_rgb.rb', line 40

def on(color)
  color = :aoi if color == :aqua
  case color
  when :red
    red_on
  when :green
    green_on
  when :blue
    blue_on
  when :yellow
    red_on
    green_on
  when :aoi
    blue_on
    green_on
  else
  end
end

#red_offObject



20
21
22
# File 'lib/led_rgb.rb', line 20

def red_off
  DigitalEffector.off @red
end

#red_onObject



16
17
18
# File 'lib/led_rgb.rb', line 16

def red_on
  DigitalEffector.on @red
end