Skip to content

Commit 6711c69

Browse files
authored
Merge pull request #13 from caternuson/master
added examples
2 parents 43e7a87 + 6fdd5e7 commit 6711c69

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

examples/simple.py

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import board
2+
import busio
3+
import adafruit_tsl2561
4+
5+
# Create the I2C bus
6+
i2c = busio.I2C(board.SCL, board.SDA)
7+
8+
# Create the TSL2561 instance, passing in the I2C bus
9+
tsl = adafruit_tsl2561.TSL2561(i2c)
10+
11+
# Print chip info
12+
print("Chip ID = {}".format(tsl.chip_id))
13+
print("Enabled = {}".format(tsl.enabled))
14+
print("Gain = {}".format(tsl.gain))
15+
print("Integration time = {}".format(tsl.integration_time))
16+
17+
print("Configuring TSL2561...")
18+
19+
# Enable the light sensor
20+
tsl.enabled = True
21+
22+
# Set gain 0=1x, 1=16x
23+
tsl.gain = 0
24+
25+
# Set integration time (0=13.7ms, 1=101ms, 2=402ms, or 3=manual)
26+
tsl.integration_time = 1
27+
28+
print("Getting readings...")
29+
30+
# Get raw (luminosity) readings individually
31+
broadband = tsl.broadband
32+
infrared = tsl.infrared
33+
34+
# Get raw (luminosity) readings using tuple unpacking
35+
#broadband, infrared = tsl.luminosity
36+
37+
# Get computed lux value
38+
lux = tsl.lux
39+
40+
# Print results
41+
print("Enabled = {}".format(tsl.enabled))
42+
print("Gain = {}".format(tsl.gain))
43+
print("Integration time = {}".format(tsl.integration_time))
44+
print("Broadband = {}".format(broadband))
45+
print("Infrared = {}".format(infrared))
46+
print("Lux = {}".format(lux))
47+
48+
# Disble the light sensor (to save power)
49+
tsl.enabled = False

0 commit comments

Comments
 (0)