💾 Archived View for capsule.adrianhesketh.com › 2019 › 09 › 29 › raspberry-pi-piezo-buzzer-with-go captured on 2021-12-03 at 14:04:38. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2021-11-30)

-=-=-=-=-=-=-

capsule.adrianhesketh.com

home

Raspberry Pi piezo buzzer with Go

I'm building a burglar alam with my son, using a Raspberry Pi Zero as the micro-controller, and using Go as the programming language.

That's led to me needing a few libraries along the way. Today's library is to play sounds using a piezo buzzer.

You can grab the code from [0]

[0]

It's easy enough to make a beep:

pin := rpio.Pin(12)
beeper.Beep(pin, 440, time.Millisecond*500)

Or you can play a tune using musical notes and a tempo.

pin := rpio.Pin(12)
bpm := 140
m := beeper.NewMusic(pin, bpm)
m.Note("A5", beeper.Quaver)
m.Note("B5", beeper.Quaver)
m.Note("D5", beeper.Quaver)
m.Note("B5", beeper.Quaver)
m.Note("F#5", beeper.Crotchet)
m.Note("F#5", beeper.Crotchet)
m.Note("E5", beeper.Crotchet)
m.Rest(beeper.Crotchet)
m.Note("A5", beeper.Quaver)
m.Note("B5", beeper.Quaver)
m.Note("D5", beeper.Quaver)
m.Note("B5", beeper.Quaver)
m.Note("E5", beeper.Crotchet)
m.Note("E5", beeper.Crotchet)
m.Note("D5", beeper.Quaver)
m.Note("C#5", beeper.Quaver)
m.Note("B4", beeper.Quaver)
m.Rest(beeper.Crotchet)
m.Note("A5", beeper.Quaver)
m.Note("B5", beeper.Quaver)
m.Note("D5", beeper.Quaver)
m.Note("B5", beeper.Quaver)
m.Note("D5", beeper.Crotchet)
m.Note("E5", beeper.Quaver)
m.Note("C#5", beeper.Quaver)
m.Rest(beeper.Quaver)
m.Note("A4", beeper.Quaver)
m.Note("E5", beeper.Crotchet)
m.Note("D5", beeper.Crotchet)

More

Next

A Go Security Journey - Gophercon UK 2019

Previous

4x4 alphanumeric keypad on the Raspberry Pi with Go

Home

home