Class: WallE::Led
- Inherits:
-
Object
- Object
- WallE::Led
- Defined in:
- lib/wall_e/components/led.rb
Instance Method Summary collapse
-
#brightness(value) ⇒ Object
Public: Set the brightness of the LED.
-
#initialize(pin) ⇒ Led
constructor
Public: Initialize an LED.
-
#off ⇒ Object
Public: Turn the LED off.
-
#off? ⇒ Boolean
Public: Indicates if the LED is current off.
-
#on ⇒ Object
Public: Turn the LED on.
-
#on? ⇒ Boolean
Public: Indicates if the LED is currently on.
-
#toggle ⇒ Object
Public: Toggle the LED on or off.
-
#value ⇒ Object
Public: The current value of the LED.
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 |
#off ⇒ Object
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.
46 47 48 |
# File 'lib/wall_e/components/led.rb', line 46 def off? !on? end |
#on ⇒ Object
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.
41 42 43 |
# File 'lib/wall_e/components/led.rb', line 41 def on? @is_on end |
#toggle ⇒ Object
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 |
#value ⇒ Object
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 |