Class: Artoo::Drivers::MakeyButton

Inherits:
Driver
  • Object
show all
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

Instance Method Summary collapse

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

#dataObject

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.

Returns:

  • (Boolean)

    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_driverObject



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