tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/examples/l3gd20/main.go (about) 1 package main 2 3 import ( 4 "machine" 5 "time" 6 7 "tinygo.org/x/drivers/l3gd20" 8 ) 9 10 func main() { 11 const ( 12 // Default address on most breakout boards. 13 pcaAddr = 0x40 14 ) 15 16 bus := machine.I2C0 17 18 err := bus.Configure(machine.I2CConfig{}) 19 if err != nil { 20 panic(err.Error()) 21 } 22 23 gyro := l3gd20.NewI2C(bus, 105) 24 err = gyro.Configure(l3gd20.Config{Range: l3gd20.Range_250}) 25 if err != nil { 26 println(err.Error()) 27 } 28 29 var x, y, z int32 30 for { 31 err = gyro.Update() 32 if err != nil { 33 println(err.Error()) 34 } 35 x, y, z = gyro.AngularVelocity() 36 println(x, y, z) 37 time.Sleep(500 * time.Millisecond) 38 } 39 }