tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/examples/tone/tone.go (about)

     1  package main
     2  
     3  import (
     4  	"machine"
     5  	"time"
     6  
     7  	"tinygo.org/x/drivers/tone"
     8  )
     9  
    10  var (
    11  	// Configuration for the Adafruit Circuit Playground Bluefruit.
    12  	pwm = machine.PWM0
    13  	pin = machine.D12
    14  )
    15  
    16  func main() {
    17  	speaker, err := tone.New(pwm, pin)
    18  	if err != nil {
    19  		println("failed to configure PWM")
    20  		return
    21  	}
    22  
    23  	// Two tone siren.
    24  	for {
    25  		println("nee")
    26  		speaker.SetNote(tone.B5)
    27  		time.Sleep(time.Second / 2)
    28  
    29  		println("naw")
    30  		speaker.SetNote(tone.A5)
    31  		time.Sleep(time.Second / 2)
    32  	}
    33  }