1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-29 13:49:14 +08:00
hybridgroup.gobot/examples/chip_tsl2561.go
Marc-Antoine Ruel 50d5869808 Fix go test ./...
Make all examples to not be built by default by adding the build tag 'example'.
Some files were automatically reformatted by goimports upon saving.
2017-03-13 11:01:39 -04:00

41 lines
713 B
Go

// +build example
//
// Do not build by default.
package main
import (
"fmt"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/i2c"
"gobot.io/x/gobot/platforms/chip"
)
func main() {
board := chip.NewAdaptor()
luxSensor := i2c.NewTSL2561Driver(board, i2c.WithTSL2561Gain16X)
work := func() {
gobot.Every(1*time.Second, func() {
broadband, ir, err := luxSensor.GetLuminocity()
if err != nil {
fmt.Println("Err:", err)
} else {
light := luxSensor.CalculateLux(broadband, ir)
fmt.Printf("BB: %v, IR: %v, Lux: %v\n", broadband, ir, light)
}
})
}
robot := gobot.NewRobot("tsl2561Bot",
[]gobot.Connection{board},
[]gobot.Device{luxSensor},
work,
)
robot.Start()
}