Class: TouchSensor
Constant Summary
Constants inherited from Sensor
Instance Attribute Summary
Attributes inherited from Brick
Instance Method Summary collapse
-
#initialize(nxt, port = NXTComm::SENSOR_1) ⇒ TouchSensor
constructor
A new instance of TouchSensor.
-
#is_pressed? ⇒ Boolean
(also: #pressed?)
Returns true if the touch sensor is pressed, false otherwise.
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 |