mirror of
https://github.com/kidoman/embd
synced 2025-01-03 10:31:36 +01:00
34 lines
501 B
Go
34 lines
501 B
Go
|
// +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)
|
||
|
}
|
||
|
|
||
|
}
|