gobot.io/x/gobot@v1.16.0/examples/edison_grove_temperature_sensor.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/aio"
    13  	"gobot.io/x/gobot/platforms/intel-iot/edison"
    14  )
    15  
    16  func main() {
    17  	board := edison.NewAdaptor()
    18  	sensor := aio.NewGroveTemperatureSensorDriver(board, "0")
    19  
    20  	work := func() {
    21  		gobot.Every(500*time.Millisecond, func() {
    22  			fmt.Println("current temp (c): ", sensor.Temperature())
    23  		})
    24  	}
    25  
    26  	robot := gobot.NewRobot("sensorBot",
    27  		[]gobot.Connection{board},
    28  		[]gobot.Device{sensor},
    29  		work,
    30  	)
    31  
    32  	robot.Start()
    33  }