tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/examples/mag3110/main.go (about) 1 // Connects to an MAG3110 I2C magnetometer. 2 package main 3 4 import ( 5 "machine" 6 "time" 7 8 "tinygo.org/x/drivers/mag3110" 9 ) 10 11 func main() { 12 machine.I2C0.Configure(machine.I2CConfig{}) 13 14 mag := mag3110.New(machine.I2C0) 15 mag.Configure() 16 17 for { 18 x, y, z := mag.ReadMagnetic() 19 println("Magnetic readings:", x, y, z) 20 21 c, _ := mag.ReadTemperature() 22 println("Temperature:", float32(c)/1000, "°C") 23 24 time.Sleep(time.Millisecond * 100) 25 } 26 }