class Tinkerforge::BrickletPiezoBuzzer

Creates 1kHz beep

Constants

CALLBACK_BEEP_FINISHED

This callback is triggered if a beep set by BrickletPiezoBuzzer#beep is finished

CALLBACK_MORSE_CODE_FINISHED

This callback is triggered if the playback of the morse code set by BrickletPiezoBuzzer#morse_code is finished.

Public Class Methods

new(uid, ipcon) click to toggle source

Creates an object with the unique device ID uid and adds it to the IP Connection ipcon.

Calls superclass method
# File lib/tinkerforge/bricklet_piezo_buzzer.rb, line 33
def initialize(uid, ipcon)
  super uid, ipcon, DEVICE_IDENTIFIER, DEVICE_DISPLAY_NAME

  @api_version = [2, 0, 0]

  @response_expected[FUNCTION_BEEP] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_MORSE_CODE] = RESPONSE_EXPECTED_FALSE
  @response_expected[FUNCTION_GET_IDENTITY] = RESPONSE_EXPECTED_ALWAYS_TRUE

  @callback_formats[CALLBACK_BEEP_FINISHED] = [8, '']
  @callback_formats[CALLBACK_MORSE_CODE_FINISHED] = [8, '']

  @ipcon.add_device self
end

Public Instance Methods

beep(duration) click to toggle source

Beeps for the given duration.

# File lib/tinkerforge/bricklet_piezo_buzzer.rb, line 49
def beep(duration)
  check_validity

  send_request FUNCTION_BEEP, [duration], 'L', 8, ''
end
get_identity() click to toggle source

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_piezo_buzzer.rb, line 78
def get_identity
  send_request FUNCTION_GET_IDENTITY, [], '', 33, 'Z8 Z8 k C3 C3 S'
end
morse_code(morse) click to toggle source

Sets morse code that will be played by the piezo buzzer. The morse code is given as a string consisting of “.” (dot), “-” (minus) and “ ” (space) for dits, dahs and pauses. Every other character is ignored.

For example: If you set the string “…—…”, the piezo buzzer will beep nine times with the durations “short short short long long long short short short”.

# File lib/tinkerforge/bricklet_piezo_buzzer.rb, line 62
def morse_code(morse)
  check_validity

  send_request FUNCTION_MORSE_CODE, [morse], 'Z60', 8, ''
end
register_callback(id, &block) click to toggle source

Registers a callback with ID id to the block block.

# File lib/tinkerforge/bricklet_piezo_buzzer.rb, line 83
def register_callback(id, &block)
  callback = block
  @registered_callbacks[id] = callback
end