Skip to content

Add threshold functionality #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 6, 2019
Merged

Conversation

caternuson
Copy link
Collaborator

Adds ability to set low/high light thresholds and configure interrupt functionality.

tsl_test

Adafruit CircuitPython 3.1.2 on 2019-01-07; Adafruit ItsyBitsy M4 Express with samd51g19
>>> import board, busio
>>> from digitalio import DigitalInOut, Direction, Pull
>>> import adafruit_tsl2561
>>> i2c = busio.I2C(board.SCL, board.SDA)
>>> tsl = adafruit_tsl2561.TSL2561(i2c)
>>> pin = DigitalInOut(board.D10)
>>> pin.direction = Direction.INPUT
>>> pin.pull = Pull.UP
>>> tsl.luminosity
(74, 12)
>>> tsl.threshold_low = 20
>>> tsl.threshold_high = 1000
>>> tsl.cycles = 2
>>> tsl.interrupt_mode = 1
>>> pin.value
True
>>> tsl.luminosity
(1796, 212)
>>> pin.value
False
>>> tsl.clear_interrupt()
>>> pin.value
True
>>> tsl.luminosity
(27, 7)
>>> tsl.luminosity
(2, 1)
>>> pin.value
False
>>> 

@caternuson caternuson requested a review from a team February 6, 2019 03:11
@caternuson caternuson mentioned this pull request Feb 6, 2019
@carterw
Copy link

carterw commented Feb 6, 2019

Would please try your code with a lower threshold of zero and tell us what behavior you see? I was finding that an interrupt was generated when the lumens dropped under 5 even when the threshold was between zero and 4.

@caternuson
Copy link
Collaborator Author

Seems OK. When the interrupt is triggered, pin.value becomes False:

>>> tsl.interrupt_mode = 1
>>> tsl.threshold_high = 5000
>>> tsl.threshold_low = 0
>>> tsl.cycles = 1
>>> tsl.clear_interrupt()
>>> tsl.luminosity, pin.value
((65, 13), True)
>>> tsl.luminosity, pin.value
((4, 1), True)
>>> tsl.luminosity, pin.value
((7, 3), True)
>>> tsl.luminosity, pin.value
((0, 0), False)
>>> 

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks @caternuson

@tannewt tannewt merged commit 511d8f6 into adafruit:master Feb 6, 2019
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Feb 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants