gobot.io/x/gobot@v1.16.0/examples/firmata_bmp180.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  	bmp180 := i2c.NewBMP180Driver(firmataAdaptor)
    20  
    21  	work := func() {
    22  		gobot.Every(1*time.Second, func() {
    23  			t, _ := bmp180.Temperature()
    24  			fmt.Println("Temperature", t)
    25  
    26  			p, _ := bmp180.Pressure()
    27  			fmt.Println("Pressure", p)
    28  		})
    29  	}
    30  
    31  	robot := gobot.NewRobot("bmp180bot",
    32  		[]gobot.Connection{firmataAdaptor},
    33  		[]gobot.Device{bmp180},
    34  		work,
    35  	)
    36  
    37  	robot.Start()
    38  }