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