gobot.io/x/gobot/v2@v2.1.0/examples/edison_grove_temperature_sensor.go (about)

     1  //go:build example
     2  // +build example
     3  
     4  //
     5  // Do not build by default.
     6  
     7  package main
     8  
     9  import (
    10  	"fmt"
    11  	"time"
    12  
    13  	"gobot.io/x/gobot/v2"
    14  	"gobot.io/x/gobot/v2/drivers/aio"
    15  	"gobot.io/x/gobot/v2/platforms/intel-iot/edison"
    16  )
    17  
    18  func main() {
    19  	board := edison.NewAdaptor()
    20  	sensor := aio.NewGroveTemperatureSensorDriver(board, "0")
    21  
    22  	work := func() {
    23  		gobot.Every(500*time.Millisecond, func() {
    24  			fmt.Println("current temp (c): ", sensor.Temperature())
    25  		})
    26  	}
    27  
    28  	robot := gobot.NewRobot("sensorBot",
    29  		[]gobot.Connection{board},
    30  		[]gobot.Device{sensor},
    31  		work,
    32  	)
    33  
    34  	robot.Start()
    35  }