Class: CheekyPi::LightInterface
- Inherits:
-
Object
- Object
- CheekyPi::LightInterface
- Defined in:
- lib/cheeky-pi/light_interface.rb
Instance Method Summary collapse
- #fetch ⇒ Object
-
#initialize(path) ⇒ LightInterface
constructor
A new instance of LightInterface.
- #set(color) ⇒ Object
Constructor Details
#initialize(path) ⇒ LightInterface
Returns a new instance of LightInterface.
5 6 7 8 9 |
# File 'lib/cheeky-pi/light_interface.rb', line 5 def initialize(path) @r = "#{path}/red" @g = "#{path}/green" @b = "#{path}/blue" end |
Instance Method Details
#fetch ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/cheeky-pi/light_interface.rb', line 11 def fetch r = IO.read(@r).to_f g = IO.read(@g).to_f b = IO.read(@b).to_f Color.create [r, g, b] end |
#set(color) ⇒ Object
20 21 22 23 24 |
# File 'lib/cheeky-pi/light_interface.rb', line 20 def set(color) IO.write(@r, color.r.round) IO.write(@g, color.g.round) IO.write(@b, color.b.round) end |