class Tinkerforge::BrickletMotionDetector
Passive infrared (PIR) motion sensor with 7m range
Constants
- CALLBACK_DETECTION_CYCLE_ENDED
This callback is called when the detection cycle ended. When this callback is called, a new motion can be detected again after approximately 2 seconds.
- CALLBACK_MOTION_DETECTED
This callback is called after a motion was detected.
Public Class Methods
Creates an object with the unique device ID uid
and adds it to the IP Connection ipcon
.
# File lib/tinkerforge/bricklet_motion_detector.rb, line 40 def initialize(uid, ipcon) super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME @api_version = [2, 0, 1] @response_expected[FUNCTION_GET_MOTION_DETECTED] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_SET_STATUS_LED_CONFIG] = RESPONSE_EXPECTED_FALSE @response_expected[FUNCTION_GET_STATUS_LED_CONFIG] = RESPONSE_EXPECTED_ALWAYS_TRUE @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE @callback_formats[CALLBACK_MOTION_DETECTED] = [8, ''] @callback_formats[CALLBACK_DETECTION_CYCLE_ENDED] = [8, ''] @ipcon.add_device self end
Public Instance Methods
Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier.
The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port). A Bricklet connected to an :ref:`Isolator Bricklet <isolator_bricklet>` is always at position 'z'.
The device identifier numbers can be found :ref:`here <device_identifier>`. |device_identifier_constant|
# File lib/tinkerforge/bricklet_motion_detector.rb, line 102 def get_identity send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S' end
Returns 1 if a motion was detected. How long this returns 1 after a motion was detected can be adjusted with one of the small potentiometers on the Motion Detector Bricklet, see :ref:`here <motion_detector_bricklet_sensitivity_delay_block_time>`.
There is also a blue LED on the Bricklet that is on as long as the Bricklet is in the “motion detected” state.
# File lib/tinkerforge/bricklet_motion_detector.rb, line 63 def get_motion_detected check_validity send_request FUNCTION_GET_MOTION_DETECTED, [], '', 9, 'C' end
Returns the configuration as set by BrickletMotionDetector#set_status_led_config
.
- .. versionadded
-
2.0.1$nbsp;(Plugin)
# File lib/tinkerforge/bricklet_motion_detector.rb, line 86 def get_status_led_config check_validity send_request FUNCTION_GET_STATUS_LED_CONFIG, [], '', 9, 'C' end
Registers a callback with ID id
to the block block
.
# File lib/tinkerforge/bricklet_motion_detector.rb, line 107 def register_callback(id, &block) callback = block @registered_callbacks[id] = callback end
Sets the status led configuration.
By default the status LED turns on if a motion is detected and off is no motion is detected.
You can also turn the LED permanently on/off.
- .. versionadded
-
2.0.1$nbsp;(Plugin)
# File lib/tinkerforge/bricklet_motion_detector.rb, line 77 def set_status_led_config(config) check_validity send_request FUNCTION_SET_STATUS_LED_CONFIG, [config], 'C', 8, '' end