Class: Smalruby::Hardware::RgbLedAnode
- Inherits:
-
Smalrubot::Components::BaseComponent
- Object
- Smalrubot::Components::BaseComponent
- Smalruby::Hardware::RgbLedAnode
- Defined in:
- lib/smalruby/hardware/rgb_led_anode.rb
Overview
RGB LED(アノード)を表現するクラス
Instance Method Summary collapse
-
#color=(val) ⇒ Object
RGB LEDを指定した色に光らせる.
-
#initialize(options) ⇒ RgbLedAnode
constructor
A new instance of RgbLedAnode.
- #stop ⇒ Object
-
#turn_off ⇒ Object
RGB LEDをオフにする.
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_smalrubot([: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
#color=(val) ⇒ Object
RGB LEDを指定した色に光らせる
21 22 23 24 25 26 27 |
# File 'lib/smalruby/hardware/rgb_led_anode.rb', line 21 def color=(val) color = Color.smalruby_to_dxruby(val) 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], Smalrubot::Board::HIGH) end |
#stop ⇒ Object
34 35 36 |
# File 'lib/smalruby/hardware/rgb_led_anode.rb', line 34 def stop turn_off end |
#turn_off ⇒ Object
RGB LEDをオフにする
30 31 32 |
# File 'lib/smalruby/hardware/rgb_led_anode.rb', line 30 def turn_off digital_write(pins[3], Smalrubot::Board::LOW) end |