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

     1  // +build example
     2  //
     3  // Do not build by default.
     4  
     5  package main
     6  
     7  import (
     8  	"fmt"
     9  	"os"
    10  	"time"
    11  
    12  	"gobot.io/x/gobot"
    13  	"gobot.io/x/gobot/drivers/i2c"
    14  	"gobot.io/x/gobot/platforms/firmata"
    15  )
    16  
    17  func main() {
    18  	firmataAdaptor := firmata.NewAdaptor(os.Args[1])
    19  	bme280 := i2c.NewBME280Driver(firmataAdaptor)
    20  
    21  	work := func() {
    22  		gobot.Every(1*time.Second, func() {
    23  			t, _ := bme280.Temperature()
    24  			fmt.Println("Temperature", t)
    25  
    26  			p, _ := bme280.Pressure()
    27  			fmt.Println("Pressure", p)
    28  
    29  			a, _ := bme280.Altitude()
    30  			fmt.Println("Altitude", a)
    31  
    32  			h, _ := bme280.Humidity()
    33  			fmt.Println("Humidity", h)
    34  		})
    35  	}
    36  
    37  	robot := gobot.NewRobot("bme280bot",
    38  		[]gobot.Connection{firmataAdaptor},
    39  		[]gobot.Device{bme280},
    40  		work,
    41  	)
    42  
    43  	robot.Start()
    44  }