1
0
mirror of https://github.com/kidoman/embd synced 2024-12-22 12:50:19 +01:00
embd/samples/bh1750fvi.go

34 lines
484 B
Go
Raw Normal View History

2014-03-02 12:36:34 +05:30
// +build ignore
2013-12-17 20:37:58 +05:30
package main
import (
"log"
"time"
"github.com/kidoman/embd/i2c"
2014-02-10 05:05:41 +05:30
"github.com/kidoman/embd/sensor/bh1750fvi"
2013-12-17 20:37:58 +05:30
)
func main() {
if err := i2c.Open(); err != nil {
panic(err)
}
defer i2c.Close()
bus := i2c.NewBus(1)
2013-12-17 20:37:58 +05:30
sensor := bh1750fvi.New(bh1750fvi.High, bus)
defer sensor.Close()
2013-12-17 20:37:58 +05:30
for {
lighting, err := sensor.Lighting()
2013-12-17 20:37:58 +05:30
if err != nil {
log.Panic(err)
}
log.Printf("Lighting is %v lx", lighting)
2013-12-17 20:37:58 +05:30
time.Sleep(500 * time.Millisecond)
}
}