seesaw: added example and smoketest

This commit is contained in:
Thomas Richner
2023-10-17 23:19:58 +02:00
committed by BCG
parent 933c9e127d
commit f7b80ef95a
7 changed files with 68 additions and 48 deletions
+29
View File
@@ -0,0 +1,29 @@
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
var buf [2]byte
err := dev.Read(seesaw.ModuleTouchBase, seesaw.FunctionTouchChannelOffset, buf[:], readDelay)
if err != nil {
panic(err)
}
moisture := uint16(buf[0])<<8 | uint16(buf[1])
println("soil moisture: " + strconv.Itoa(int(moisture)))
}