mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-07-26 10:38:41 +00:00
857ab80ae6
Adds the necessary function addresses for reading and writing encoders on a seesaw. Also provides two helper functions to make this easier.
34 lines
784 B
Go
34 lines
784 B
Go
package main
|
|
|
|
import (
|
|
"machine"
|
|
"strconv"
|
|
"time"
|
|
|
|
"tinygo.org/x/drivers/seesaw"
|
|
)
|
|
|
|
const readDelay = time.Microsecond * 3000
|
|
|
|
// example reading soil moisture with an Adafruit capacitive soil-sensor (4026) powered by a seesaw
|
|
// https://learn.adafruit.com/adafruit-stemma-soil-sensor-i2c-capacitive-moisture-sensor/overview
|
|
func main() {
|
|
machine.I2C0.Configure(machine.I2CConfig{})
|
|
|
|
dev := seesaw.New(machine.I2C0)
|
|
|
|
dev.Address = 0x36
|
|
|
|
// the soil sensor is especially slow, let's give it some more time
|
|
dev.ReadDelay = readDelay
|
|
|
|
var buf [2]byte
|
|
err := dev.Read(seesaw.ModuleTouchBase, seesaw.FunctionTouchChannelOffset, buf[:])
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
moisture := uint16(buf[0])<<8 | uint16(buf[1])
|
|
|
|
println("soil moisture: " + strconv.Itoa(int(moisture)))
|
|
}
|