Class: Smalruby::Hardware::Button
- Inherits:
-
Dino::Components::Button
- Object
- Dino::Components::Button
- Smalruby::Hardware::Button
- Defined in:
- lib/smalruby/hardware/button.rb
Overview
ボタンを表現するクラス
Instance Method Summary collapse
- #down? ⇒ Boolean (also: #off?)
-
#initialize(options) ⇒ Button
constructor
A new instance of Button.
-
#not_use_pullup ⇒ Object
プルアップ抵抗を使わない.
- #stop ⇒ Object
- #up? ⇒ Boolean (also: #on?)
Constructor Details
#initialize(options) ⇒ Button
Returns a new instance of Button.
8 9 10 11 12 |
# File 'lib/smalruby/hardware/button.rb', line 8 def initialize() @using_pullup = true super(board: world.board, pin: Pin.smalruby_to_dino([:pin]), pullup: true) end |
Instance Method Details
#down? ⇒ Boolean Also known as: off?
30 31 32 |
# File 'lib/smalruby/hardware/button.rb', line 30 def down? !up? end |
#not_use_pullup ⇒ Object
プルアップ抵抗を使わない
15 16 17 18 |
# File 'lib/smalruby/hardware/button.rb', line 15 def not_use_pullup @using_pullup = false board.set_pullup(pin, false) end |
#stop ⇒ Object
20 21 22 |
# File 'lib/smalruby/hardware/button.rb', line 20 def stop @board.remove_digital_hardware(self) end |
#up? ⇒ Boolean Also known as: on?
24 25 26 |
# File 'lib/smalruby/hardware/button.rb', line 24 def up? @using_pullup ? @state == DOWN : @state == UP end |