Class: RubyBuzz::Light

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_buzz/light.rb

Overview

Each Pad has one LED light under the buzzer button.

There are four Light objects, each controls one of these lights.

Accessed via Pad:

RubyBuzz::Pad.light`

Controlled individually:

Controlled together:

  • RubyBuzz::Light.all_on

  • RubyBuzz::Light.all_off

Constant Summary collapse

@@lights =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index) ⇒ Light

Initialize a buzzer by index 0 to 3.

Arguments:

  • index - Integer, 0 to 3, which light does this represent.



33
34
35
36
# File 'lib/ruby_buzz/light.rb', line 33

def initialize(index)
  @file = `ls /sys/class/leds/*buzz#{index + 1}/brightness`
  @@lights << self
end

Instance Attribute Details

#fileObject

Returns the value of attribute file.



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

def file
  @file
end

Class Method Details

.all_offObject

Turn all lights off



57
58
59
60
# File 'lib/ruby_buzz/light.rb', line 57

def self.all_off
  @@lights.each{|l|l.off}
  return nil
end

.all_onObject

Turn all lights on



65
66
67
68
# File 'lib/ruby_buzz/light.rb', line 65

def self.all_on
  @@lights.each{|l|l.on }
  return nil
end

Instance Method Details

#offObject

Turn the light off



49
50
51
52
# File 'lib/ruby_buzz/light.rb', line 49

def off
  `echo 0 > #{file}`
  return nil
end

#onObject

Turn the light on



41
42
43
44
# File 'lib/ruby_buzz/light.rb', line 41

def on
  `echo 1 > #{file}`
  return nil
end