gobot.io/x/gobot@v1.16.0/examples/edison_bme280.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/intel-iot/edison" 14 ) 15 16 func main() { 17 a := edison.NewAdaptor() 18 bme280 := i2c.NewBME280Driver(a, i2c.WithAddress(0x76)) 19 20 work := func() { 21 gobot.Every(1*time.Second, func() { 22 t, e := bme280.Temperature() 23 fmt.Println("Temperature", t) 24 if e != nil { 25 fmt.Println(e) 26 } 27 28 p, e := bme280.Pressure() 29 fmt.Println("Pressure", p) 30 if e != nil { 31 fmt.Println(e) 32 } 33 34 a, e := bme280.Altitude() 35 fmt.Println("Altitude", a) 36 if e != nil { 37 fmt.Println(e) 38 } 39 40 h, e := bme280.Humidity() 41 fmt.Println("Humidity", h) 42 if e != nil { 43 fmt.Println(e) 44 } 45 }) 46 } 47 48 robot := gobot.NewRobot("bme280bot", 49 []gobot.Connection{a}, 50 []gobot.Device{bme280}, 51 work, 52 ) 53 54 err := robot.Start() 55 if err != nil { 56 fmt.Println(err) 57 } 58 }