Class: Artoo::Drivers::Led

Inherits:
Driver
  • Object
show all
Defined in:
lib/artoo/drivers/led.rb

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

#parent

Instance Method Summary collapse

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

Parameters:



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.

Returns:

  • (Boolean)

    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.

Returns:

  • (Boolean)

    True if on



11
12
13
# File 'lib/artoo/drivers/led.rb', line 11

def is_on?
  (@is_on ||= false) == true
end

#offObject

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

#onObject

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

#toggleObject

Toggle status

Examples:

on > off, off > on



36
37
38
# File 'lib/artoo/drivers/led.rb', line 36

def toggle
  is_off? ? on : off
end