Skip to content
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

Use the LUX sensor to automatically set brightness #628

Closed
wants to merge 1 commit into from

Conversation

LionsPhil
Copy link
Contributor

Combine the board features in the suggested fashion in the most featureful badge example. Read the photosensor and set the display brightness accordingly.

@LionsPhil
Copy link
Contributor Author

(This is tested on my Tufty2040, since I don't see an automatic build test for that.)

@LionsPhil
Copy link
Contributor Author

Hmm. The pylint check is simply saying Error: with no findings. Local pylint has a lot of findings, but they're with the existing codebase. I don't believe I'm regressing here.

@ahnlak
Copy link
Contributor

ahnlak commented Jan 12, 2023

Looks like it doesn't like your line break in

   display.set_backlight(BACKLIGHT_LOW +
        (luminance_frac * (BACKLIGHT_HIGH - BACKLIGHT_LOW)))

@LionsPhil
Copy link
Contributor Author

Weird, I don't get that finding locally. Looks like this check is also failing on other contempoary PRs in the same way, so I assume it's an infra problem and leave the commits as-is for now.

@ZodiusInfuser ZodiusInfuser added [- tufty2040 -] https://shop.pimoroni.com/products/tufty-2040 micropython This issue or request relates to micropython (either code or bindings) labels Jan 20, 2023
@Gadgetoid
Copy link
Member

We're linting with flake8 which may have a difference of opinion with pylint.

Run with:

flake8 --show-source --ignore E501

Combine the board features in the suggested fashion in the most
featureful badge example. Read the photosensor and set the display
brightness accordingly.
@LionsPhil
Copy link
Contributor Author

LionsPhil commented Feb 12, 2023

There we go; ahnlak was indeed correct:

micropython/examples/tufty2040/retro_badge.py:155:41: W504 line break after binary operator
    display.set_backlight(BACKLIGHT_LOW +
                                        ^
micropython/examples/tufty2040/retro_badge.py:156:9: E128 continuation line under-indented for visual indent
        (luminance_frac * (BACKLIGHT_HIGH - BACKLIGHT_LOW)))
        ^

Line rewrapped in a way it's happy with.
(Can you bug the premerge check not giving this output?)

@helgibbons helgibbons self-assigned this Feb 13, 2023
@Gadgetoid
Copy link
Member

@helgibbons dare I ask if you managed to test this 👀

@helgibbons
Copy link
Contributor

This (and #629 ) works - thanks @LionsPhil , and super-thanks for fixing the Tufty launcher! However, I'm finding it quite flickery at certain brightness levels. I think the LED lights in this office may be the culprit, as I've just wandered round the building and under different kinds of lights it's absolutely fine. Could be possible to add more averaging/sampling to improve this behaviour, perhaps?

It might be a good idea to have the brightness/battery adjusting version as a separate example due to the added complexity, but if we are adding it to the default example it might be best to have this functionality turned off by default. I really like the dimming being connected to both light level and battery level though :)

@helgibbons
Copy link
Contributor

Here's a video which hopefully shows the flickering a little:
https://user-images.githubusercontent.com/50950368/221248391-9ad2dafe-6268-4812-9207-812bfbeb7c71.mp4

@LionsPhil
Copy link
Contributor Author

Ah yeah, that's annoying. Alright, my actual personal badge example has a combination of these which iterates on them a bunch, including some smoothing; I'll see if I can pull that out as a standalone example. I assume it's cleanest to make that a separate PR and retract these two?

@helgibbons
Copy link
Contributor

Sounds good, thanks!

LionsPhil added a commit to LionsPhil/pimoroni-pico that referenced this pull request Mar 2, 2023
Standalone smoothed display auto-brightness, reactive to the on-board
LUX and battery ADC sensors, with debugging keys so it's easier to test
(and play with).

Closes pull requests pimoroni#628 and pimoroni#629, which did this to the retro_badge
example, but made it too complicated.
@Gadgetoid
Copy link
Member

Replaced with #701

@Gadgetoid Gadgetoid closed this Mar 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[- tufty2040 -] https://shop.pimoroni.com/products/tufty-2040 micropython This issue or request relates to micropython (either code or bindings)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants