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

     1  package main
     2  
     3  import (
     4  	"machine"
     5  	"time"
     6  
     7  	"tinygo.org/x/drivers/adxl345"
     8  )
     9  
    10  func main() {
    11  	machine.I2C0.Configure(machine.I2CConfig{})
    12  	sensor := adxl345.New(machine.I2C0)
    13  	sensor.Configure()
    14  
    15  	println("ADXL345 starts")
    16  	for {
    17  		x, y, z, _ := sensor.ReadAcceleration()
    18  		println("X:", x, "Y:", y, "Z:", z)
    19  
    20  		rx, ry, rz := sensor.ReadRawAcceleration()
    21  		println("X (raw):", rx, "Y (raw):", ry, "Z (raw):", rz)
    22  
    23  		time.Sleep(100 * time.Millisecond)
    24  	}
    25  }