1
0
mirror of https://github.com/kidoman/embd synced 2024-06-06 11:07:48 +02:00
embd/samples/ina219.go
2016-05-19 19:48:57 -06:00

50 lines
679 B
Go

// +build ignore
package main
import (
"flag"
"fmt"
"time"
"github.com/kidoman/embd"
"github.com/kidoman/embd/sensor/ina219"
_ "github.com/kidoman/embd/host/all"
)
func main() {
flag.Parse()
if err := embd.InitI2C(); err != nil {
panic(err)
}
defer embd.CloseI2C()
bus := embd.NewI2CBus(1)
ina := ina219.New(bus, 0x40, 0.1)
defer ina.Close()
for {
sv, err := ina.ShuntVoltage()
if err != nil {
panic(err)
}
v, err := ina.Voltage()
if err != nil {
panic(err)
}
c, err := ina.Current()
if err != nil {
panic(err)
}
fmt.Printf("Shunt Voltage=%v Voltage=%v Current=%v\n", sv, v, c)
time.Sleep(500 * time.Millisecond)
}
}