mirror of
https://github.com/kidoman/embd
synced 2025-07-03 03:47:33 +02:00
support for MCP4725 DAC
This commit is contained in:
parent
7d044a8f0e
commit
1017bc7f9a
3 changed files with 149 additions and 2 deletions
36
samples/mcp4725.go
Normal file
36
samples/mcp4725.go
Normal file
|
@ -0,0 +1,36 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"math/rand"
|
||||
"os"
|
||||
"os/signal"
|
||||
|
||||
"github.com/kid0m4n/go-rpi/controller/mcp4725"
|
||||
"github.com/kid0m4n/go-rpi/i2c"
|
||||
)
|
||||
|
||||
func main() {
|
||||
bus, err := i2c.NewBus(1)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
|
||||
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 {
|
||||
log.Printf("mcp4725: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue