forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
edison_bme280.go
58 lines (48 loc) · 927 Bytes
/
edison_bme280.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// +build example
//
// Do not build by default.
package main
import (
"fmt"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/i2c"
"gobot.io/x/gobot/platforms/intel-iot/edison"
)
func main() {
a := edison.NewAdaptor()
bme280 := i2c.NewBME280Driver(a, i2c.WithAddress(0x76))
work := func() {
gobot.Every(1*time.Second, func() {
t, e := bme280.Temperature()
fmt.Println("Temperature", t)
if e != nil {
fmt.Println(e)
}
p, e := bme280.Pressure()
fmt.Println("Pressure", p)
if e != nil {
fmt.Println(e)
}
a, e := bme280.Altitude()
fmt.Println("Altitude", a)
if e != nil {
fmt.Println(e)
}
h, e := bme280.Humidity()
fmt.Println("Humidity", h)
if e != nil {
fmt.Println(e)
}
})
}
robot := gobot.NewRobot("bme280bot",
[]gobot.Connection{a},
[]gobot.Device{bme280},
work,
)
err := robot.Start()
if err != nil {
fmt.Println(err)
}
}