Class: WallE::Led

Inherits:
Object
  • Object
show all
Defined in:
lib/wall_e/components/led.rb

Instance Method Summary collapse

Constructor Details

#initialize(pin) ⇒ Led

Public: Initialize an LED

pin - the Pin the LED is attached to.



7
8
9
10
# File 'lib/wall_e/components/led.rb', line 7

def initialize(pin)
  @pin = pin
  @is_on = false
end

Instance Method Details

#brightness(value) ⇒ Object

Public: Set the brightness of the LED.

Returns nothing.



33
34
35
36
# File 'lib/wall_e/components/led.rb', line 33

def brightness(value)
  @pin.set_mode(Pin::PWM)
  @pin.analog_write(value)
end

#offObject

Public: Turn the LED off.

Returns nothing.



24
25
26
27
28
# File 'lib/wall_e/components/led.rb', line 24

def off
  @pin.set_mode(Pin::OUTPUT)
  @pin.digital_write(Pin::LOW)
  @is_on = false
end

#off?Boolean

Public: Indicates if the LED is current off.

Returns:

  • (Boolean)


46
47
48
# File 'lib/wall_e/components/led.rb', line 46

def off?
  !on?
end

#onObject

Public: Turn the LED on.

Returns nothing.



15
16
17
18
19
# File 'lib/wall_e/components/led.rb', line 15

def on
  @pin.set_mode(Pin::OUTPUT)
  @pin.digital_write(Pin::HIGH)
  @is_on = true
end

#on?Boolean

Public: Indicates if the LED is currently on.

Returns Boolean.

Returns:

  • (Boolean)


41
42
43
# File 'lib/wall_e/components/led.rb', line 41

def on?
  @is_on
end

#toggleObject

Public: Toggle the LED on or off.

Returns nothing.



53
54
55
56
57
58
59
# File 'lib/wall_e/components/led.rb', line 53

def toggle
  if on?
    off
  else
    on
  end
end

#valueObject

Public: The current value of the LED.

Returns Integer value.



64
65
66
# File 'lib/wall_e/components/led.rb', line 64

def value
  @pin.value
end