Class: Dino::Components::RgbLed
- Inherits:
-
BaseComponent
- Object
- BaseComponent
- Dino::Components::RgbLed
- Defined in:
- lib/dino/components/rgb_led.rb
Constant Summary collapse
- COLORS =
Format: [R, G, B]
{ red: [255, 000, 000], green: [000, 255, 000], blue: [000, 000, 255], cyan: [000, 255, 255], yellow: [255, 255, 000], magenta: [255, 000, 255], white: [255, 255, 255], off: [000, 000, 000] }
Instance Attribute Summary
Attributes inherited from BaseComponent
Instance Method Summary collapse
-
#after_initialize(options = {}) ⇒ Object
options = my_board, pins: {red: red_pin, green: green_pin, blue: blue_pin.
- #blinky ⇒ Object
Methods inherited from BaseComponent
Constructor Details
This class inherits a constructor from Dino::Components::BaseComponent
Instance Method Details
#after_initialize(options = {}) ⇒ Object
options = my_board, pins: {red: red_pin, green: green_pin, blue: blue_pin
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/dino/components/rgb_led.rb', line 5 def after_initialize(={}) raise 'missing pins[:red] pin' unless self.pins[:red] raise 'missing pins[:green] pin' unless self.pins[:green] raise 'missing pins[:blue] pin' unless self.pins[:blue] pins.each do |color, pin| set_pin_mode(pin, :out) analog_write(pin, Board::LOW) end end |
#blinky ⇒ Object
36 37 38 39 40 41 |
# File 'lib/dino/components/rgb_led.rb', line 36 def blinky [:red, :green, :blue].cycle do |color| self.send(color) sleep(0.01) end end |