github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/examples/pdm/pdm.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "machine" 6 ) 7 8 var ( 9 audio = make([]int16, 16) 10 pdm = machine.PDM{} 11 ) 12 13 func main() { 14 machine.BUTTONA.Configure(machine.PinConfig{Mode: machine.PinInputPulldown}) 15 err := pdm.Configure(machine.PDMConfig{CLK: machine.PDM_CLK_PIN, DIN: machine.PDM_DIN_PIN}) 16 if err != nil { 17 panic(fmt.Sprintf("Failed to configure PDM:%v", err)) 18 } 19 20 for { 21 if machine.BUTTONA.Get() { 22 println("Recording new audio clip into memory") 23 pdm.Read(audio) 24 println(fmt.Sprintf("Recorded new audio clip into memory: %v", audio)) 25 } 26 } 27 }