mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-07 00:13:42 +00:00
Driver for ADXL345 3-axis digital accelerometer (#33)
* Driver for ADXL345 3-axis digital accelerometer
This commit is contained in:
committed by
Ron Evans
parent
f6bdc9734f
commit
ed2d334d55
@@ -0,0 +1,26 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"github.com/tinygo-org/drivers/adxl345"
|
||||
)
|
||||
|
||||
func main() {
|
||||
machine.I2C0.Configure(machine.I2CConfig{})
|
||||
sensor := adxl345.New(machine.I2C0)
|
||||
sensor.Configure()
|
||||
|
||||
println("ADXL345 starts")
|
||||
for {
|
||||
sensor.Update()
|
||||
x, y, z := sensor.Acceleration()
|
||||
println("X:", x, "Y:", y, "Z:", z)
|
||||
|
||||
rx, ry, rz := sensor.RawXYZ()
|
||||
println("X (raw):", rx, "Y (raw):", ry, "Z (raw):", rz)
|
||||
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user