Class: RPiRGB
- Inherits:
-
Object
- Object
- RPiRGB
- Defined in:
- lib/rpi_rgb.rb
Overview
rgb = RPiRGB.new(%w(4 17 27), presets: [100,100,0]) rgb.color = ‘white’ sleep 2 rgb.color = ‘purple’ sleep 2 rgb.color = ‘green’
Instance Attribute Summary collapse
-
#blue ⇒ Object
readonly
Returns the value of attribute blue.
-
#brightness ⇒ Object
Returns the value of attribute brightness.
-
#green ⇒ Object
readonly
Returns the value of attribute green.
-
#red ⇒ Object
readonly
Returns the value of attribute red.
Instance Method Summary collapse
- #colour ⇒ Object (also: #color)
- #colour=(val) ⇒ Object (also: #color=)
-
#initialize(pins, brightness: 100, smooth: false, presets: nil) ⇒ RPiRGB
constructor
A new instance of RPiRGB.
- #mix(*values) ⇒ Object
- #off ⇒ Object
Constructor Details
#initialize(pins, brightness: 100, smooth: false, presets: nil) ⇒ RPiRGB
Returns a new instance of RPiRGB.
26 27 28 29 30 31 32 33 34 |
# File 'lib/rpi_rgb.rb', line 26 def initialize(pins, brightness: 100, smooth: false, presets: nil) @red, @green, @blue = pins.map do |x| RPiLed.new(x, brightness: brightness, smooth: smooth) end @brightness, @presets = brightness, presets end |
Instance Attribute Details
#blue ⇒ Object (readonly)
Returns the value of attribute blue.
24 25 26 |
# File 'lib/rpi_rgb.rb', line 24 def blue @blue end |
#brightness ⇒ Object
Returns the value of attribute brightness.
23 24 25 |
# File 'lib/rpi_rgb.rb', line 23 def brightness @brightness end |
#green ⇒ Object (readonly)
Returns the value of attribute green.
24 25 26 |
# File 'lib/rpi_rgb.rb', line 24 def green @green end |
#red ⇒ Object (readonly)
Returns the value of attribute red.
24 25 26 |
# File 'lib/rpi_rgb.rb', line 24 def red @red end |
Instance Method Details
#colour ⇒ Object Also known as: color
75 76 77 |
# File 'lib/rpi_rgb.rb', line 75 def colour() @colour end |
#colour=(val) ⇒ Object Also known as: color=
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/rpi_rgb.rb', line 46 def colour=(val) @colour = val case val when 'red' mix 100, 0, 0 when 'green' mix 0, 100, 0 when 'blue' mix 0, 0, 100 when 'white' mix 100, 100, 100 else return unless @presets preset = @presets[val.to_sym] mix(preset) if preset end end |
#mix(*values) ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/rpi_rgb.rb', line 82 def mix(*values) r, g, b = values.flatten.map {|v| v / (100 / @brightness ) } [@red, @green, @blue].each(&:on) red.brightness, green.brightness, blue.brightness = r, g, b end |
#off ⇒ Object
91 92 93 |
# File 'lib/rpi_rgb.rb', line 91 def off() [@red, @green, @blue].each(&:off) end |