tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/examples/seesaw/main.go (about) 1 package main 2 3 import ( 4 "machine" 5 "strconv" 6 "time" 7 8 "tinygo.org/x/drivers/seesaw" 9 ) 10 11 const readDelay = time.Microsecond * 3000 12 13 // example reading soil moisture with an Adafruit capacitive soil-sensor (4026) powered by a seesaw 14 // https://learn.adafruit.com/adafruit-stemma-soil-sensor-i2c-capacitive-moisture-sensor/overview 15 func main() { 16 machine.I2C0.Configure(machine.I2CConfig{}) 17 18 dev := seesaw.New(machine.I2C0) 19 20 dev.Address = 0x36 21 22 // the soil sensor is especially slow, let's give it some more time 23 dev.ReadDelay = readDelay 24 25 var buf [2]byte 26 err := dev.Read(seesaw.ModuleTouchBase, seesaw.FunctionTouchChannelOffset, buf[:]) 27 if err != nil { 28 panic(err) 29 } 30 moisture := uint16(buf[0])<<8 | uint16(buf[1]) 31 32 println("soil moisture: " + strconv.Itoa(int(moisture))) 33 }