1
0
mirror of https://github.com/kidoman/embd synced 2024-06-16 15:49:53 +02:00
embd/samples/bmp180.go
2014-01-01 03:10:32 +05:30

39 lines
631 B
Go

package main
import (
"log"
"time"
"github.com/kid0m4n/go-rpi/i2c"
"github.com/kid0m4n/go-rpi/sensor/bmp180"
)
func main() {
bus, err := i2c.NewBus(1)
if err != nil {
log.Panic(err)
}
baro := bmp180.New(bus)
defer baro.Close()
for {
temp, err := baro.Temperature()
if err != nil {
log.Panic(err)
}
log.Printf("Temp is %v", temp)
pressure, err := baro.Pressure()
if err != nil {
log.Panic(err)
}
log.Printf("Pressure is %v", pressure)
altitude, err := baro.Altitude()
if err != nil {
log.Panic(err)
}
log.Printf("Altitude is %v", altitude)
time.Sleep(500 * time.Millisecond)
}
}