mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-16 04:43:25 +00:00
feat: add support for seesaw encoders
Adds the necessary function addresses for reading and writing encoders on a seesaw. Also provides two helper functions to make this easier.
This commit is contained in:
committed by
deadprogram
parent
a31ba26a6c
commit
857ab80ae6
@@ -0,0 +1,33 @@
|
||||
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)))
|
||||
}
|
||||
Reference in New Issue
Block a user