Class: Artoo::Drivers::Led

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

Overview

The LED driver behaviors

Instance Attribute Summary

Attributes inherited from Driver

#parent

Instance Method Summary collapse

Methods inherited from Driver

#connection, #event_topic_name, #initialize, #interval, #method_missing, #pin, #start_driver

Methods included from Celluloid

#timers

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



31
32
33
34
# File 'lib/artoo/drivers/led.rb', line 31

def brightness(level=0)
  connection.set_pin_mode(pin, Firmata::Board::PWM)
  connection.analog_write(pin, level)
end

#is_off?Boolean

Returns:

  • (Boolean)


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

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

#is_on?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/artoo/drivers/led.rb', line 7

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

#offObject



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

def off
  @is_on = false
  connection.set_pin_mode(pin, Firmata::Board::OUTPUT)
  connection.digital_write(pin, Firmata::Board::LOW)
end

#onObject



15
16
17
18
19
# File 'lib/artoo/drivers/led.rb', line 15

def on
  @is_on = true
  connection.set_pin_mode(pin, Firmata::Board::OUTPUT)
  connection.digital_write(pin, Firmata::Board::HIGH)
end

#toggleObject



27
28
29
# File 'lib/artoo/drivers/led.rb', line 27

def toggle
  is_off? ? on : off
end