Class: RPiLed
- Inherits:
-
RPiPwm
- Object
- RPiPwm
- RPiLed
- Defined in:
- lib/rpi_led.rb
Instance Attribute Summary collapse
-
#brightness ⇒ Object
(also: #bright)
Returns the value of attribute brightness.
Instance Method Summary collapse
- #brighter ⇒ Object
- #brightest ⇒ Object
- #dimmer ⇒ Object
- #dimmest ⇒ Object
-
#initialize(pin_num, brightness: 100, smooth: true) ⇒ RPiLed
constructor
A new instance of RPiLed.
Constructor Details
#initialize(pin_num, brightness: 100, smooth: true) ⇒ RPiLed
Returns a new instance of RPiLed.
13 14 15 16 17 18 19 |
# File 'lib/rpi_led.rb', line 13 def initialize(pin_num, brightness: 100, smooth: true) @smooth = smooth @brightness = @duty_cycle super(pin_num.to_i, duty_cycle: brightness) end |
Instance Attribute Details
#brightness ⇒ Object Also known as: bright
Returns the value of attribute brightness.
11 12 13 |
# File 'lib/rpi_led.rb', line 11 def brightness @brightness end |
Instance Method Details
#brighter ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/rpi_led.rb', line 21 def brighter() return if @brightness == 100 increase = @brightness <= 90 ? 10 : 100 - @brightness self.brightness = @brightness + increase end |
#brightest ⇒ Object
29 30 31 |
# File 'lib/rpi_led.rb', line 29 def brightest() self.brightness = 100 end |
#dimmer ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/rpi_led.rb', line 51 def dimmer() return if @brightness <= 2 decrease = brightness > 10 ? 10 : 2 self.brightness = @brightness - decrease end |
#dimmest ⇒ Object
59 60 61 |
# File 'lib/rpi_led.rb', line 59 def dimmest() self.brightness = 0.1 end |