gobot.io/x/gobot@v1.16.0/examples/raspi_ads1015.go (about)

     1  // +build example
     2  //
     3  // Do not build by default.
     4  
     5  package main
     6  
     7  import (
     8  	"fmt"
     9  	"time"
    10  
    11  	"gobot.io/x/gobot"
    12  	"gobot.io/x/gobot/drivers/i2c"
    13  	"gobot.io/x/gobot/platforms/raspi"
    14  )
    15  
    16  func main() {
    17  	a := raspi.NewAdaptor()
    18  	ads1015 := i2c.NewADS1015Driver(a)
    19  	// Adjust the gain to be able to read values of at least 5V
    20  	ads1015.DefaultGain, _ = ads1015.BestGainForVoltage(5.0)
    21  
    22  	work := func() {
    23  		gobot.Every(100*time.Millisecond, func() {
    24  			v, _ := ads1015.ReadWithDefaults(0)
    25  			fmt.Println("A0", v)
    26  		})
    27  	}
    28  
    29  	robot := gobot.NewRobot("ads1015bot",
    30  		[]gobot.Connection{a},
    31  		[]gobot.Device{ads1015},
    32  		work,
    33  	)
    34  
    35  	robot.Start()
    36  }