Class: Artoo::Drivers::Led
- Inherits:
-
Driver
- Object
- Driver
- Artoo::Drivers::Led
- Defined in:
- lib/artoo/drivers/led.rb
Overview
The LED driver behaviors
Constant Summary collapse
- COMMANDS =
[:on, :off, :toggle, :brightness, :on?, :off?].freeze
Instance Method Summary collapse
-
#brightness(level = 0) ⇒ Object
Change brightness level.
-
#initialize(params = {}) ⇒ Led
constructor
A new instance of Led.
-
#off ⇒ Object
Sets led to level LOW.
-
#off? ⇒ Boolean
True if off.
-
#on ⇒ Object
Sets led to level HIGH.
-
#on? ⇒ Boolean
True if on.
-
#toggle ⇒ Object
Toggle status.
Constructor Details
#initialize(params = {}) ⇒ Led
Returns a new instance of Led.
12 13 14 15 |
# File 'lib/artoo/drivers/led.rb', line 12 def initialize(params = {}) @is_on = false super end |
Instance Method Details
#brightness(level = 0) ⇒ Object
Change brightness level
49 50 51 |
# File 'lib/artoo/drivers/led.rb', line 49 def brightness(level=0) connection.pwm_write(pin, level) end |
#off ⇒ Object
Sets led to level LOW
35 36 37 38 39 |
# File 'lib/artoo/drivers/led.rb', line 35 def off change_state(pin, :low) @is_on = false true end |
#off? ⇒ Boolean
Returns True if off.
23 24 25 |
# File 'lib/artoo/drivers/led.rb', line 23 def off? (not on?) end |
#on ⇒ Object
Sets led to level HIGH
28 29 30 31 32 |
# File 'lib/artoo/drivers/led.rb', line 28 def on change_state(pin, :high) @is_on = true true end |
#on? ⇒ Boolean
Returns True if on.
18 19 20 |
# File 'lib/artoo/drivers/led.rb', line 18 def on? @is_on end |
#toggle ⇒ Object
Toggle status
43 44 45 |
# File 'lib/artoo/drivers/led.rb', line 43 def toggle on? ? off : on end |