Class: Artoo::Drivers::Led
Overview
The LED driver behaviors
Constant Summary collapse
- COMMANDS =
[:is_on?, :is_off?, :on, :off, :toggle, :brightness].freeze
Instance Attribute Summary
Attributes inherited from Driver
Instance Method Summary collapse
-
#brightness(level = 0) ⇒ Object
Change brightness level.
-
#is_off? ⇒ Boolean
True if off.
-
#is_on? ⇒ Boolean
True if on.
-
#off ⇒ Object
Sets led to off status.
-
#on ⇒ Object
Sets led to on status.
-
#toggle ⇒ Object
Toggle status.
Methods inherited from Driver
#command, #commands, #connection, #event_topic_name, #initialize, #interval, #known_command?, #method_missing, #pin, #start_driver
Constructor Details
This class inherits a constructor from Artoo::Drivers::Driver
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Artoo::Drivers::Driver
Instance Method Details
#brightness(level = 0) ⇒ Object
Change brightness level
42 43 44 45 |
# File 'lib/artoo/drivers/led.rb', line 42 def brightness(level=0) connection.set_pin_mode(pin, Firmata::Board::PWM) connection.analog_write(pin, level) end |
#is_off? ⇒ Boolean
Returns True if off.
16 17 18 |
# File 'lib/artoo/drivers/led.rb', line 16 def is_off? (@is_on ||= false) == false end |
#is_on? ⇒ Boolean
Returns True if on.
11 12 13 |
# File 'lib/artoo/drivers/led.rb', line 11 def is_on? (@is_on ||= false) == true end |
#off ⇒ Object
Sets led to off status
28 29 30 31 32 |
# File 'lib/artoo/drivers/led.rb', line 28 def off @is_on = false connection.set_pin_mode(pin, Firmata::Board::OUTPUT) connection.digital_write(pin, Firmata::Board::LOW) end |
#on ⇒ Object
Sets led to on status
21 22 23 24 25 |
# File 'lib/artoo/drivers/led.rb', line 21 def on @is_on = true connection.set_pin_mode(pin, Firmata::Board::OUTPUT) connection.digital_write(pin, Firmata::Board::HIGH) end |
#toggle ⇒ Object
Toggle status
36 37 38 |
# File 'lib/artoo/drivers/led.rb', line 36 def toggle is_off? ? on : off end |