Class: Artoo::Drivers::MakeyButton
- Inherits:
-
Driver
- Object
- Driver
- Artoo::Drivers::MakeyButton
- Defined in:
- lib/artoo/drivers/makey_button.rb
Overview
MakeyButton driver behaviors
Constant Summary collapse
- COMMANDS =
[:is_pressed?].freeze
- DOWN =
1
- UP =
0
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ MakeyButton
constructor
A new instance of MakeyButton.
-
#is_pressed? ⇒ Boolean
True if pressed.
- #start_driver ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ MakeyButton
Returns a new instance of MakeyButton.
14 15 16 17 18 |
# File 'lib/artoo/drivers/makey_button.rb', line 14 def initialize(params={}) super @data = [] end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
12 13 14 |
# File 'lib/artoo/drivers/makey_button.rb', line 12 def data @data end |
Instance Method Details
#is_pressed? ⇒ Boolean
Returns True if pressed.
21 22 23 |
# File 'lib/artoo/drivers/makey_button.rb', line 21 def is_pressed? (@pressed_val == 1) ? true : false end |
#start_driver ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/artoo/drivers/makey_button.rb', line 25 def start_driver @pressed_val = 0 every(0.1) do new_value = connection.digital_read(pin) unless new_value.nil? @data << new_value @data.shift if @data.size > 5 update(new_value) end end super end |