mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-08 17:03:39 +00:00
tone: add package for producing tones using the PWM interface
This commit is contained in:
committed by
Ron Evans
parent
6bc466f79b
commit
df343190c2
@@ -0,0 +1,33 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/tone"
|
||||
)
|
||||
|
||||
var (
|
||||
// Configuration for the Adafruit Circuit Playground Bluefruit.
|
||||
pwm = machine.PWM0
|
||||
pin = machine.D12
|
||||
)
|
||||
|
||||
func main() {
|
||||
speaker, err := tone.New(pwm, pin)
|
||||
if err != nil {
|
||||
println("failed to configure PWM")
|
||||
return
|
||||
}
|
||||
|
||||
// Two tone siren.
|
||||
for {
|
||||
println("nee")
|
||||
speaker.SetNote(tone.B5)
|
||||
time.Sleep(time.Second / 2)
|
||||
|
||||
println("naw")
|
||||
speaker.SetNote(tone.A5)
|
||||
time.Sleep(time.Second / 2)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user