gobot.io/x/gobot@v1.16.0/examples/raspi_sht3x.go (about)

     1  // +build example
     2  //
     3  // Do not build by default.
     4  
     5  package main
     6  
     7  import (
     8  	"fmt"
     9  	"time"
    10  
    11  	"gobot.io/x/gobot"
    12  	"gobot.io/x/gobot/drivers/i2c"
    13  	"gobot.io/x/gobot/platforms/raspi"
    14  )
    15  
    16  func main() {
    17  	r := raspi.NewAdaptor()
    18  	sht3x := i2c.NewSHT3xDriver(r)
    19  
    20  	work := func() {
    21  		sht3x.Units = "F"
    22  		sht3x.Start()
    23  		sn, err := sht3x.SerialNumber()
    24  		fmt.Printf("Serial Number: 0x%08x, err: %v\n", sn, err)
    25  
    26  		gobot.Every(5*time.Second, func() {
    27  			temp, rh, err := sht3x.Sample()
    28  			fmt.Printf("Temp: %f F, Relative Humidity: %f, err: %v\n", temp, rh, err)
    29  		})
    30  	}
    31  
    32  	robot := gobot.NewRobot("SHT3xbot",
    33  		[]gobot.Connection{r},
    34  		[]gobot.Device{sht3x},
    35  		work,
    36  	)
    37  
    38  	robot.Start()
    39  }