gobot.io/x/gobot/v2@v2.1.0/examples/chip_tsl2561.go (about) 1 //go:build example 2 // +build example 3 4 // 5 // Do not build by default. 6 7 package main 8 9 import ( 10 "fmt" 11 "time" 12 13 "gobot.io/x/gobot/v2" 14 "gobot.io/x/gobot/v2/drivers/i2c" 15 "gobot.io/x/gobot/v2/platforms/chip" 16 ) 17 18 func main() { 19 board := chip.NewAdaptor() 20 luxSensor := i2c.NewTSL2561Driver(board, i2c.WithTSL2561Gain16X) 21 22 work := func() { 23 gobot.Every(1*time.Second, func() { 24 broadband, ir, err := luxSensor.GetLuminocity() 25 26 if err != nil { 27 fmt.Println("Err:", err) 28 } else { 29 light := luxSensor.CalculateLux(broadband, ir) 30 fmt.Printf("BB: %v, IR: %v, Lux: %v\n", broadband, ir, light) 31 } 32 }) 33 } 34 35 robot := gobot.NewRobot("tsl2561Bot", 36 []gobot.Connection{board}, 37 []gobot.Device{luxSensor}, 38 work, 39 ) 40 41 robot.Start() 42 }