Buzzer

Buzzer

new Buzzer(pin, active_high, initial_value)

Source:
Represents a digital buzzer component.
Example
const Buzzer = require ('gpiozero').Buzzer;
         bz = new Buzzer(3);
         bz.on();
Parameters:
Name Type Description
pin int | Pin The GPIO pin which the buzzer is attached to.
active_high boolean If ``true`` (the default), the buzzer will operate normally with the circuit described above. If ``false`` you should wire the cathode to the GPIO pin, and the anode to a 3V3 pin.
initial_value boolean If ``false`` (the default), the buzzer will be silent initially. If ``undefined``, the buzzer will be left in whatever state the pin is found in when configured for output (warning: this can be on). If ``true``, the buzzer will be switched on initially.

Extends

Methods

active_high(valueopt)

Source:
Inherited From:
This property can be set after construction; be warned that changing it will invert value (i.e. changing this property doesn't change the device's pin state - it just changes how that state is interpreted).
Parameters:
Name Type Attributes Description
value boolean <optional>
When ``true``, the value property is ``true`` when the device's pin is high. When ``false`` the value property is ``true`` when the device's pin is low (i.e. the value is inverted).

beep()

Source:
Make the buzzer switch on and off once a second.
Source:
Inherited From:
Make the device turn on and off repeatedly.
Parameters:
Name Type Description
on_time float Number of seconds on. Defaults to 1 second.
off_time float Number of seconds off. Defaults to 1 second.
n int Number of times to blink; ``None`` (the default) means forever.
{@callback} callback - Function to be called upon completion in the form (error, data).

close()

Source:
Inherited From:
Close the device and remove the pin allocation allowing it to be reused.

closed() → {boolean}

Source:
Inherited From:
Returns:
- Is ``true`` is no pin is allocated.
Type
boolean

is_active() → {boolean}

Source:
Inherited From:
Returns:
- Is true is the device value is currently set.
Type
boolean

off()

Source:
Inherited From:
Turns the device off.

on()

Source:
Inherited From:
Turns the device on.

pin() → {undefined|*|int|Pin}

Source:
Inherited From:
Returns:
- The Pin that the device is connected to. This will be ``undefined`` if the device has been closed (see the :meth:`close` method). When dealing with GPIO pins, query ``pin.number`` to discover the GPIO pin (in BCM numbering) that the device is connected to.
Type
undefined | * | int | Pin

toggle()

Source:
Inherited From:
Reverse the state of the device. If it's on, turn it off; if it's off, turn it on.

toString() → {string}

Source:
Inherited From:
Returns:
- Description of the device.
Type
string

value(valueopt) → {boolean|float}

Source:
Inherited From:
Parameters:
Name Type Attributes Description
value boolean | float <optional>
When supplied the device output is changed to the value.
Returns:
- When value is undefined, the function returns the current value of the device.
Type
boolean | float