forked from mstahl/tsl2591
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tsl2591.go
58 lines (45 loc) · 915 Bytes
/
tsl2591.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* tsl2591 - A command for interacting with TSL2591 lux sensors.
*/
package main
import (
"fmt"
"log"
"time"
"github.com/jimnelson2/tsl2591"
)
const Interval = 1 * time.Second
func main() {
tsl, err := tsl2591.NewTSL2591(&tsl2591.Opts{
Gain: tsl2591.GainMed,
Timing: tsl2591.Integrationtime600MS,
})
if err != nil {
panic(err)
}
defer tsl.Disable()
ticker := time.NewTicker(Interval)
for {
lux, err := tsl.Lux()
if err != nil {
log.Panic(err)
}
fmt.Printf("Total Light: %f lux\n", lux)
ir, err := tsl.Infrared()
if err != nil {
log.Panic(err)
}
fmt.Printf("Infrared light: %d\n", ir)
visible, err := tsl.Visible()
if err != nil {
log.Panic(err)
}
fmt.Printf("Visible light: %d\n", visible)
full, err := tsl.FullSpectrum()
if err != nil {
log.Panic(err)
}
fmt.Printf("Full spectrum (IR + visible) light: %d\n", full)
<-ticker.C
}
}