Class: TouchSensor

Inherits:
Sensor show all
Defined in:
lib/sensors/touch_sensor.rb

Constant Summary

Constants inherited from Sensor

Sensor::POLL_INTERVAL

Instance Attribute Summary

Attributes inherited from Brick

#log, #port

Instance Method Summary collapse

Methods inherited from Sensor

#name, #off, #read_data, #set_input_mode, #wait_for_event

Constructor Details

#initialize(nxt, port = NXTComm::SENSOR_1) ⇒ TouchSensor



23
24
25
26
# File 'lib/sensors/touch_sensor.rb', line 23

def initialize(nxt, port = NXTComm::SENSOR_1)
  super(nxt, port)
  set_input_mode(NXTComm::SWITCH, NXTComm::BOOLEANMODE)
end

Instance Method Details

#is_pressed?Boolean Also known as: pressed?

Returns true if the touch sensor is pressed, false otherwise. (The sensor seems to read as “pressed” when it is pushed in about half way)



30
31
32
# File 'lib/sensors/touch_sensor.rb', line 30

def is_pressed?
  read_data[:value_scaled] > 0
end