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

     1  package main
     2  
     3  import (
     4  	"machine"
     5  	"time"
     6  
     7  	"tinygo.org/x/drivers/lis2mdl"
     8  )
     9  
    10  func main() {
    11  	machine.I2C0.Configure(machine.I2CConfig{})
    12  	compass := lis2mdl.New(machine.I2C0)
    13  
    14  	if !compass.Connected() {
    15  		for {
    16  			println("LIS2MDL not connected!")
    17  			time.Sleep(1 * time.Second)
    18  		}
    19  	}
    20  
    21  	compass.Configure(lis2mdl.Configuration{}) //default settings
    22  
    23  	for {
    24  		heading := compass.ReadCompass()
    25  		println("Heading:", heading)
    26  
    27  		time.Sleep(time.Millisecond * 100)
    28  	}
    29  }