1
0
Fork 0
mirror of https://github.com/kidoman/embd synced 2025-07-03 11:57:38 +02:00

mcp3008: changes to use external spiBus

This commit is contained in:
kunalpowar 2014-05-08 23:28:29 +05:30
parent 1bb2bac8f1
commit dbc97bd15c
2 changed files with 15 additions and 24 deletions

View file

@ -8,17 +8,23 @@ import (
"time"
"github.com/kidoman/embd/convertors/mcp3008"
"github.com/kidoman/embd"
)
func main() {
flag.Parse()
fmt.Println("This is a sample code for mcp3008 10bit 8 channel ADC")
fmt.Println("this is a sample code for mcp3008 10bit 8 channel ADC")
adc, err := mcp3008.New(mcp3008.SingleMode, 0, 1000000)
if err != nil {
if err := embd.InitSPI(); err != nil {
panic(err)
}
defer adc.Close()
defer embd.CloseSPI()
spiBus := embd.NewSPIBus(embd.SpiMode0, 0, 1000000, 8, 0)
defer spiBus.Close()
adc := mcp3008.New(mcp3008.SingleMode, spiBus)
for i := 0; i < 20; i++ {
time.Sleep(1 * time.Second)
@ -27,7 +33,7 @@ func main() {
panic(err)
}
fmt.Printf("Analog value is: %v\n", val)
fmt.Printf("analog value is: %v\n", val)
}
}