Class: Smalruby::Hardware::RgbLedAnode
- Inherits:
-
Dino::Components::BaseComponent
- Object
- Dino::Components::BaseComponent
- Smalruby::Hardware::RgbLedAnode
- Defined in:
- lib/smalruby/hardware/rgb_led_anode.rb
Overview
RGB LED(アノード)を表現するクラス
Instance Method Summary collapse
-
#initialize(options) ⇒ RgbLedAnode
constructor
A new instance of RgbLedAnode.
-
#off ⇒ Object
RGB LEDをオフにする.
-
#on(options = {}) ⇒ Object
RGB LEDをオンにする.
- #stop ⇒ Object
Constructor Details
#initialize(options) ⇒ RgbLedAnode
Returns a new instance of RgbLedAnode.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/smalruby/hardware/rgb_led_anode.rb', line 8 def initialize() pin = Pin.smalruby_to_dino([:pin]) case pin when 3..6 super(board: world.board, pin: [3, 5, 6, 4]) when 9..12 super(board: world.board, pin: [9, 10, 11, 12]) else fail "RGB LED(anode)のピン番号が間違っています: {options[:pin]}" end end |
Instance Method Details
#off ⇒ Object
RGB LEDをオフにする
35 36 37 |
# File 'lib/smalruby/hardware/rgb_led_anode.rb', line 35 def off digital_write(pins[3], Dino::Board::LOW) end |
#on(options = {}) ⇒ Object
RGB LEDをオンにする
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/smalruby/hardware/rgb_led_anode.rb', line 21 def on( = {}) defaults = { color: 'white' } opts = Util.(, defaults) color = Color.smalruby_to_dxruby(opts[:color]) analog_write(pins[0], calc_value(color[0])) analog_write(pins[1], calc_value(color[1])) analog_write(pins[2], calc_value(color[2])) digital_write(pins[3], Dino::Board::HIGH) end |
#stop ⇒ Object
39 40 41 |
# File 'lib/smalruby/hardware/rgb_led_anode.rb', line 39 def stop off end |