|
|
|
|
@ -2,14 +2,13 @@
|
|
|
|
|
// Use of this source code is governed under the Apache License, Version 2.0
|
|
|
|
|
// that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
package example
|
|
|
|
|
package adxl345
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"log"
|
|
|
|
|
"periph.io/x/conn/v3/i2c/i2creg"
|
|
|
|
|
"periph.io/x/conn/v3/spi/spireg"
|
|
|
|
|
"periph.io/x/devices/v3/adxl345"
|
|
|
|
|
"periph.io/x/host/v3"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
@ -34,7 +33,7 @@ func I2C(addr uint16) {
|
|
|
|
|
|
|
|
|
|
defer p.Close()
|
|
|
|
|
|
|
|
|
|
d, err := adxl345.NewI2C(p, addr, &adxl345.DefaultOpts)
|
|
|
|
|
d, err := NewI2C(p, addr, &DefaultOpts)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
@ -55,7 +54,7 @@ func Spi() {
|
|
|
|
|
|
|
|
|
|
defer p.Close()
|
|
|
|
|
|
|
|
|
|
d, err := adxl345.NewSpi(p, &adxl345.DefaultOpts)
|
|
|
|
|
d, err := NewSpi(p, &DefaultOpts)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
@ -72,7 +71,7 @@ func mustInitHost() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// measure reads the acceleration values every 30ms for <duration> seconds
|
|
|
|
|
func measure(d *adxl345.Dev, duration time.Duration) {
|
|
|
|
|
func measure(d *Dev, duration time.Duration) {
|
|
|
|
|
|
|
|
|
|
fmt.Println(d.String())
|
|
|
|
|
|