Package com.tinkerforge
Class BrickletPiezoSpeaker
- java.lang.Object
-
- com.tinkerforge.DeviceBase
-
- com.tinkerforge.Device
-
- com.tinkerforge.BrickletPiezoSpeaker
-
public class BrickletPiezoSpeaker extends Device
Creates beep with configurable frequency
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
BrickletPiezoSpeaker.BeepFinishedListener
This listener is triggered if a beep set bybeep(long, int)
is finishedstatic interface
BrickletPiezoSpeaker.MorseCodeFinishedListener
This listener is triggered if the playback of the morse code set bymorseCode(String, int)
is finished.-
Nested classes/interfaces inherited from class com.tinkerforge.Device
Device.Identity
-
-
Field Summary
Fields Modifier and Type Field Description static long
BEEP_DURATION_INFINITE
static long
BEEP_DURATION_OFF
static java.lang.String
DEVICE_DISPLAY_NAME
static int
DEVICE_IDENTIFIER
static byte
FUNCTION_BEEP
static byte
FUNCTION_CALIBRATE
static byte
FUNCTION_GET_IDENTITY
static byte
FUNCTION_MORSE_CODE
-
Constructor Summary
Constructors Constructor Description BrickletPiezoSpeaker(java.lang.String uid, IPConnection ipcon)
Creates an object with the unique device ID \c uid.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addBeepFinishedListener(BrickletPiezoSpeaker.BeepFinishedListener listener)
Adds a BeepFinished listener.void
addMorseCodeFinishedListener(BrickletPiezoSpeaker.MorseCodeFinishedListener listener)
Adds a MorseCodeFinished listener.void
beep(long duration, int frequency)
Beeps with the given frequency for the given duration.boolean
calibrate()
The Piezo Speaker Bricklet can play 512 different tones.Device.Identity
getIdentity()
Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier.void
morseCode(java.lang.String morse, int frequency)
Sets morse code that will be played by the piezo buzzer.void
removeBeepFinishedListener(BrickletPiezoSpeaker.BeepFinishedListener listener)
Removes a BeepFinished listener.void
removeMorseCodeFinishedListener(BrickletPiezoSpeaker.MorseCodeFinishedListener listener)
Removes a MorseCodeFinished listener.-
Methods inherited from class com.tinkerforge.DeviceBase
getAPIVersion, getResponseExpected, setResponseExpected, setResponseExpectedAll
-
-
-
-
Field Detail
-
DEVICE_IDENTIFIER
public static final int DEVICE_IDENTIFIER
- See Also:
- Constant Field Values
-
DEVICE_DISPLAY_NAME
public static final java.lang.String DEVICE_DISPLAY_NAME
- See Also:
- Constant Field Values
-
FUNCTION_BEEP
public static final byte FUNCTION_BEEP
- See Also:
- Constant Field Values
-
FUNCTION_MORSE_CODE
public static final byte FUNCTION_MORSE_CODE
- See Also:
- Constant Field Values
-
FUNCTION_CALIBRATE
public static final byte FUNCTION_CALIBRATE
- See Also:
- Constant Field Values
-
FUNCTION_GET_IDENTITY
public static final byte FUNCTION_GET_IDENTITY
- See Also:
- Constant Field Values
-
BEEP_DURATION_OFF
public static final long BEEP_DURATION_OFF
- See Also:
- Constant Field Values
-
BEEP_DURATION_INFINITE
public static final long BEEP_DURATION_INFINITE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
BrickletPiezoSpeaker
public BrickletPiezoSpeaker(java.lang.String uid, IPConnection ipcon)
Creates an object with the unique device ID \c uid. and adds it to the IP Connection \c ipcon.
-
-
Method Detail
-
beep
public void beep(long duration, int frequency) throws TinkerforgeException
Beeps with the given frequency for the given duration. .. versionchanged:: 2.0.2$nbsp;(Plugin) A duration of 0 stops the current beep if any, the frequency parameter is ignored. A duration of 4294967295 results in an infinite beep. The Piezo Speaker Bricklet can only approximate the frequency, it will play the best possible match by applying the calibration (seecalibrate()
).- Throws:
TinkerforgeException
-
morseCode
public void morseCode(java.lang.String morse, int frequency) throws TinkerforgeException
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".- Throws:
TinkerforgeException
-
calibrate
public boolean calibrate() throws TinkerforgeException
The Piezo Speaker Bricklet can play 512 different tones. This function plays each tone and measures the exact frequency back. The result is a mapping between setting value and frequency. This mapping is stored in the EEPROM and loaded on startup. The Bricklet should come calibrated, you only need to call this function (once) every time you reflash the Bricklet plugin. Returns *true* after the calibration finishes.- Throws:
TinkerforgeException
-
getIdentity
public Device.Identity getIdentity() throws TinkerforgeException
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|- Specified by:
getIdentity
in classDevice
- Throws:
TinkerforgeException
-
addBeepFinishedListener
public void addBeepFinishedListener(BrickletPiezoSpeaker.BeepFinishedListener listener)
Adds a BeepFinished listener.
-
removeBeepFinishedListener
public void removeBeepFinishedListener(BrickletPiezoSpeaker.BeepFinishedListener listener)
Removes a BeepFinished listener.
-
addMorseCodeFinishedListener
public void addMorseCodeFinishedListener(BrickletPiezoSpeaker.MorseCodeFinishedListener listener)
Adds a MorseCodeFinished listener.
-
removeMorseCodeFinishedListener
public void removeMorseCodeFinishedListener(BrickletPiezoSpeaker.MorseCodeFinishedListener listener)
Removes a MorseCodeFinished listener.
-
-