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 =
[:on, :off, :toggle, 
:brightness, 
:on?, :off?].freeze

Instance Method Summary collapse

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

Parameters:

  • level (Integer) (defaults to: 0)


49
50
51
# File 'lib/artoo/drivers/led.rb', line 49

def brightness(level=0)
  connection.pwm_write(pin, level)
end

#offObject

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.

Returns:

  • (Boolean)

    True if off



23
24
25
# File 'lib/artoo/drivers/led.rb', line 23

def off?
  (not on?)
end

#onObject

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.

Returns:

  • (Boolean)

    True if on



18
19
20
# File 'lib/artoo/drivers/led.rb', line 18

def on?
  @is_on
end

#toggleObject

Toggle status

Examples:

on > off, off > on



43
44
45
# File 'lib/artoo/drivers/led.rb', line 43

def toggle
  on? ? off : on
end