-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
speaker.go
40 lines (31 loc) · 871 Bytes
/
speaker.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package gopherhelmet
import (
"machine"
"tinygo.org/x/drivers/buzzer"
)
// SpeakerDevice is the Gopherbot speaker.
type SpeakerDevice struct {
buzzer.Device
}
// Speaker returns the SpeakerDevice.
func Speaker() *SpeakerDevice {
speakerShutdown := speakerEnablePin
speakerShutdown.Configure(machine.PinConfig{Mode: machine.PinOutput})
speakerShutdown.High()
speaker := speakerPin
speaker.Configure(machine.PinConfig{Mode: machine.PinOutput})
bzr := buzzer.New(speaker)
return &SpeakerDevice{bzr}
}
// Bleep makes a bleep sound using the speaker.
func (s *SpeakerDevice) Bleep() {
s.Tone(buzzer.C3, buzzer.Eighth)
}
// Bloop makes a bloop sound using the speaker.
func (s *SpeakerDevice) Bloop() {
s.Tone(buzzer.C5, buzzer.Quarter)
}
// Blip makes a blip sound using the speaker.
func (s *SpeakerDevice) Blip() {
s.Tone(buzzer.C6, buzzer.Eighth/8)
}