activebuzzer

package module
v0.0.0-...-df85641 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 18, 2020 License: MIT Imports: 1 Imported by: 0

README

Active Buzzer

Go Reference golangci-lint Go Report Card

Package activebuzzer is a driver allowing to control an active buzzer from GPIO pin

Documentation

For full documentation, please visit Go Reference

Quick start

import (
	"fmt"

	"github.com/raspberrypi-go-drivers/button"
	"github.com/stianeikeland/go-rpio/v4"
)

func main() {
	err := rpio.Open()
	if err != nil {
		fmt.Println("impossible to init gpio")
		os.Exit(1)
	}
	defer rpio.Close()
	// buzzer connected to GPIO pin 17
	buzzer := activebuzzer.NewActiveBuzzer(17)
	buzzer.Tone()
	time.Sleep(3 * time.Second)
	buzzer.StopTone()

Raspberry Pi compatibility

This driver has has only been tested on an Raspberry Pi Zero WH using integrated bluetooth but may work well on other Raspberry Pi having integrated Bluetooth

License

MIT License


Special thanks to @stianeikeland

This driver is based on his work in stianeikeland/go-rpio

Documentation

Overview

Package activebuzzer is a driver allowing to control an avtive buzzer from GPIO pin

Example
err := rpio.Open()
if err != nil {
	fmt.Println("impossible to init gpio")
	os.Exit(1)
}
defer rpio.Close()
// buzzer connected to GPIO pin 17
buzzer := activebuzzer.NewActiveBuzzer(17)
buzzer.Tone()
time.Sleep(3 * time.Second)
buzzer.StopTone()
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActiveBuzzer

type ActiveBuzzer struct {
	// contains filtered or unexported fields
}

ActiveBuzzer represent an active buzzer

func NewActiveBuzzer

func NewActiveBuzzer(pinID int) *ActiveBuzzer

NewActiveBuzzer creates a new ActiveBuzzer instance

Example
err := rpio.Open()
if err != nil {
	fmt.Println("impossible to init gpio")
	os.Exit(1)
}
defer rpio.Close()
// buzzer connected to GPIO pin 17
buzzer := activebuzzer.NewActiveBuzzer(17)
buzzer.Tone()
Output:

func (*ActiveBuzzer) StopTone

func (buzzer *ActiveBuzzer) StopTone()

StopTone stops the buzzer tone

Example
err := rpio.Open()
if err != nil {
	fmt.Println("impossible to init gpio")
	os.Exit(1)
}
defer rpio.Close()
// buzzer connected to GPIO pin 17
buzzer := activebuzzer.NewActiveBuzzer(17)
buzzer.Tone()
buzzer.StopTone()
Output:

func (*ActiveBuzzer) ToggleTone

func (buzzer *ActiveBuzzer) ToggleTone()

ToggleTone toggle the buzzer tone Tone if stopped and stopped is toned

Example
err := rpio.Open()
if err != nil {
	fmt.Println("impossible to init gpio")
	os.Exit(1)
}
defer rpio.Close()
// buzzer connected to GPIO pin 17
buzzer := activebuzzer.NewActiveBuzzer(17)
for i := 0; i < 10; i++ {
	buzzer.ToggleTone()
}
Output:

func (*ActiveBuzzer) Tone

func (buzzer *ActiveBuzzer) Tone()

Tone activate the buzzer tone

Example
err := rpio.Open()
if err != nil {
	fmt.Println("impossible to init gpio")
	os.Exit(1)
}
defer rpio.Close()
// buzzer connected to GPIO pin 17
buzzer := activebuzzer.NewActiveBuzzer(17)
buzzer.Tone()
Output:

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL