Package com.diozero.devices
Class Buzzer
- java.lang.Object
-
- com.diozero.api.GpioDevice
-
- com.diozero.api.DigitalOutputDevice
-
- com.diozero.devices.Buzzer
-
- All Implemented Interfaces:
DeviceInterface
,AutoCloseable
public class Buzzer extends DigitalOutputDevice
Represents a digital buzzer component.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.diozero.api.DigitalOutputDevice
DigitalOutputDevice.Builder
-
-
Field Summary
-
Fields inherited from class com.diozero.api.DigitalOutputDevice
INFINITE_ITERATIONS
-
Fields inherited from class com.diozero.api.GpioDevice
pinInfo
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
beep()
Beep repeatedly in a background thread.void
beep(float onTime, float offTime, int n, boolean background)
Beep.-
Methods inherited from class com.diozero.api.DigitalOutputDevice
close, getCycleCount, isActiveHigh, isOn, off, on, onOffLoop, setOn, setValue, stopOnOffLoop, toggle
-
Methods inherited from class com.diozero.api.GpioDevice
getGpio
-
-
-
-
Constructor Detail
-
Buzzer
public Buzzer(int gpio) throws RuntimeIOException
- Parameters:
gpio
- The GPIO to which the buzzer is attached to.- Throws:
RuntimeIOException
- If an I/O error occurred.
-
Buzzer
public Buzzer(int gpio, boolean activeHigh) throws RuntimeIOException
- Parameters:
gpio
- The GPIO to which the buzzer is attached to.activeHigh
- Set to true if a high output value represents on.- Throws:
RuntimeIOException
- If an I/O error occurred.
-
-
Method Detail
-
beep
public void beep() throws RuntimeIOException
Beep repeatedly in a background thread.- Throws:
RuntimeIOException
- If an I/O error occurred.
-
beep
public void beep(float onTime, float offTime, int n, boolean background) throws RuntimeIOException
Beep.- Parameters:
onTime
- On time in seconds.offTime
- Off time in seconds.n
- Number of iterations. Set to <0 to beep indefinitelybackground
- If true start a background thread to control the blink and return immediately. If false, only return once the blink iterations have finished.- Throws:
RuntimeIOException
- If an I/O error occurred.
-
-