initial bring up of ui lux sensor

This commit is contained in:
KemoNine 2020-08-25 18:55:05 -04:00
parent 3810641021
commit 19c192f0e3
4 changed files with 62 additions and 0 deletions

BIN
cmd/ui/ui Executable file

Binary file not shown.

44
cmd/ui/ui.go Normal file
View file

@ -0,0 +1,44 @@
package main
import (
"time"
i2c "github.com/d2r2/go-i2c"
bh1750 "github.com/d2r2/go-bh1750"
logger "github.com/d2r2/go-logger"
)
var lg = logger.NewPackageLogger("main",
logger.ErrorLevel,
)
func main() {
defer logger.FinalizeLogger()
logger.ChangePackageLogLevel("i2c", logger.ErrorLevel)
logger.ChangePackageLogLevel("bh1750", logger.ErrorLevel)
// Create new connection to I2C to bh1750
i2c, err := i2c.NewI2C(0x23, 1)
if err != nil { lg.Fatal(err) }
// Free I2C connection on exit
defer i2c.Close()
// Setup sensor
sensor := bh1750.NewBH1750()
// Reset sensor prior to use
err = sensor.Reset(i2c)
if err != nil { lg.Fatal(err) }
// Read sensor value over time
for {
resolution := bh1750.HighResolution
lux, err := sensor.MeasureAmbientLight(i2c, resolution)
if err != nil { lg.Fatal(err) }
println("Illuminance:", lux, "lx")
time.Sleep(500 * time.Millisecond)
}
}

10
go.mod Normal file
View file

@ -0,0 +1,10 @@
module kemonine.info/PiFrame
go 1.15
require (
github.com/d2r2/go-bh1750 v0.0.0-20181222061755-1195122364ab
github.com/d2r2/go-i2c v0.0.0-20191123181816-73a8a799d6bc
github.com/d2r2/go-logger v0.0.0-20181221090742-9998a510495e
github.com/davecgh/go-spew v1.1.1 // indirect
)

8
go.sum Normal file
View file

@ -0,0 +1,8 @@
github.com/d2r2/go-bh1750 v0.0.0-20181222061755-1195122364ab h1:8zeQTn3owfeyIA5KIhtvcj9wlMStdFaxbYwPkWhGVgo=
github.com/d2r2/go-bh1750 v0.0.0-20181222061755-1195122364ab/go.mod h1:3atw7ac57A1fKlJIGeLBaeXdh80Revqk6uVl7bZyH10=
github.com/d2r2/go-i2c v0.0.0-20191123181816-73a8a799d6bc h1:HLRSIWzUGMLCq4ldt0W1GLs3nnAxa5EGoP+9qHgh6j0=
github.com/d2r2/go-i2c v0.0.0-20191123181816-73a8a799d6bc/go.mod h1:AwxDPnsgIpy47jbGXZHA9Rv7pDkOJvQbezPuK1Y+nNk=
github.com/d2r2/go-logger v0.0.0-20181221090742-9998a510495e h1:ZG3JBA6rPRl0xxQ+nNSfO7tor8w+CNCTs05DNJQYbLM=
github.com/d2r2/go-logger v0.0.0-20181221090742-9998a510495e/go.mod h1:oA+9PUt8F1aKJ6o4YU1T120i7sgo1T6/1LWEEBy0BSs=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=