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

mcp3008: added package and samples for mcp3008 10-bit 8-channel adc

This commit is contained in:
kunalpowar 2014-05-03 21:35:09 +05:30
parent 42033238e2
commit 59958d7dfc
7 changed files with 163 additions and 4 deletions

33
samples/mcp3008.go Normal file
View file

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