1
0
mirror of https://github.com/kidoman/embd synced 2024-11-13 21:18:55 +01:00
embd/samples/mcp4725.go

46 lines
655 B
Go
Raw Normal View History

2014-03-02 08:06:34 +01:00
// +build ignore
2014-01-05 21:56:45 +01:00
package main
import (
"flag"
"fmt"
2014-01-05 21:56:45 +01:00
"math/rand"
"os"
"os/signal"
2014-03-02 20:21:23 +01:00
"github.com/kidoman/embd"
2014-02-10 00:35:41 +01:00
"github.com/kidoman/embd/controller/mcp4725"
_ "github.com/kidoman/embd/host/all"
2014-01-05 21:56:45 +01:00
)
func main() {
flag.Parse()
2014-03-02 20:21:23 +01:00
if err := embd.InitI2C(); err != nil {
panic(err)
}
2014-03-02 20:21:23 +01:00
defer embd.CloseI2C()
2014-03-02 20:21:23 +01:00
bus := embd.NewI2CBus(1)
2014-01-05 21:56:45 +01:00
dac := mcp4725.New(bus, 0x62)
defer dac.Close()
stop := make(chan os.Signal, 1)
signal.Notify(stop, os.Interrupt, os.Kill)
for {
select {
case <-stop:
return
default:
voltage := rand.Intn(4096)
if err := dac.SetVoltage(voltage); err != nil {
fmt.Printf("mcp4725: %v\n", err)
2014-01-05 21:56:45 +01:00
}
}
}
}