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

     1  // Connects to a LIS3DH I2C accelerometer on the Adafruit Circuit Playground Express.
     2  package main
     3  
     4  import (
     5  	"machine"
     6  	"time"
     7  
     8  	"tinygo.org/x/drivers/lis3dh"
     9  )
    10  
    11  var i2c = machine.I2C1
    12  
    13  func main() {
    14  	i2c.Configure(machine.I2CConfig{SCL: machine.SCL1_PIN, SDA: machine.SDA1_PIN})
    15  
    16  	accel := lis3dh.New(i2c)
    17  	accel.Address = lis3dh.Address1 // address on the Circuit Playground Express
    18  	accel.Configure()
    19  	accel.SetRange(lis3dh.RANGE_2_G)
    20  
    21  	println(accel.Connected())
    22  
    23  	for {
    24  		x, y, z, _ := accel.ReadAcceleration()
    25  		println("X:", x, "Y:", y, "Z:", z)
    26  
    27  		rx, ry, rz := accel.ReadRawAcceleration()
    28  		println("X (raw):", rx, "Y (raw):", ry, "Z (raw):", rz)
    29  
    30  		time.Sleep(time.Millisecond * 100)
    31  	}
    32  }