Thanks to visit codestin.com
Credit goes to github.com

Skip to content

adding display button example #21

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 3 commits into from
Mar 22, 2022

Conversation

FoamyGuy
Copy link
Contributor

@FoamyGuy FoamyGuy commented Mar 5, 2022

adds a new example that illustrates the usage of Display_Button with asyncio using some blinking vectorio.Circle objects instead of blinking LEDs and physical momentary switches.

count -= 1


async def monitor_color_button(button, button_state):
Copy link

Choose a reason for hiding this comment

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

Is there any way to prevent this coroutine from reading touches on the other buttons? I think it would be better to have a single coroutine reading the touch screen events.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The latest commit refactors the touch handling into a single coroutine that calls the separate handle functions for each of the button types.

Copy link

Choose a reason for hiding this comment

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

LGTM!

@kmatch98
Copy link

I tested on the PyPortal and found one weirdness that I can't explain. If I keep pressing the "invert colors" button a lot, pretty fast. Eventually the green button disappears and never returns. I suspect that it's going transparent and somehow not retriggering a "make_opaque". But an initial look in the code didn't turn up a clear answer.

It's a minor issue but was strange.


# use built-in display
display = board.DISPLAY

Copy link

Choose a reason for hiding this comment

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

Needed a display.rotation = 0 here or the touch position didn't match the display after being changed in a different piece of code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ordinarily the display will default to 0 rotation but since the display stays alive after the circuitpython VM instance is gone or restarts it would keep it's rotation if it did get changed.

It would be good practice to include the explict code to set it back to 0 just in case it has been changed in the users environment. I'll add a commit now. with this change. Thanks for the suggestion.

@aioue
Copy link

aioue commented Mar 22, 2022

Eventually the green button disappears and never returns.

If you don't touch anything it will eventually disappear after about 15 seconds.

Recorded screen: https://youtu.be/5gCUo6tLKzg

@FoamyGuy
Copy link
Contributor Author

FoamyGuy commented Mar 22, 2022

Thanks for the testing and feedback everyone! Much appreciated!

@aioue Thanks for recording this and sharing the video. and @kmatch98 if this is the same issue you noticed.

In this case the green circle intentionally disappears after a while. On line 308 in the example:

blink(palette_2, interval_2, 20, color_btn_state)

The 3rd argument indicates the number of times to run the blink action. This is set to 20, so the green circle blinks 20 times and then disappears and isn't shown again. I included this one to show an example of tasks that operate a certain number of times and then conclude.

This code was originall inpspired by the LED examples in the cooperative multi-tasking guide: https://learn.adafruit.com/cooperative-multitasking-in-circuitpython-with-asyncio/concurrent-tasks#two-leds-3106214-5 which are coded with a very similar count argument that controls how many times the blink should occur.

The blue circle uses -1 for the count which is a special value that makes it infiite / loop forever so it will continue blinking forever without stopping after a certain count:

blink(palette_1, interval_1, -1, color_btn_state)

@aioue
Copy link

aioue commented Mar 22, 2022

LGTM, keen to see this get merged and improved on - the other PyPortal UI guide doesn't use async and is somewhat laggy 😄

@FoamyGuy FoamyGuy merged commit 2982513 into adafruit:main Mar 22, 2022
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Mar 23, 2022
Updating https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_SH1106 to 1.2.3 from 1.2.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_DisplayIO_SH1106#9 from tekktrik/dev/remove-int
  > Merge pull request adafruit/Adafruit_CircuitPython_DisplayIO_SH1106#8 from tekktrik/dev/change-data-to-bytes
  > Fixed readthedocs build
  > Post-patch cleanup pt 2
  > Post-patch cleanup
  > Consolidate Documentation sections of README

Updating https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_SH1107 to 1.5.2 from 1.5.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_DisplayIO_SH1107#13 from tekktrik/dev/change-data-to-bytes
  > Fixed readthedocs build
  > Consolidate Documentation sections of README

Updating https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_SSD1306 to 1.5.3 from 1.5.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_DisplayIO_SSD1306#26 from tekktrik/dev/change-data-to-bytes
  > Fixed readthedocs build
  > Post-patch cleanup
  > Consolidate Documentation sections of README

Updating https://github.com/adafruit/Adafruit_CircuitPython_FocalTouch to 1.4.0 from 1.3.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_FocalTouch#25 from winneymj/main

Updating https://github.com/adafruit/Adafruit_CircuitPython_SSD1322 to 1.3.1 from 1.3.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_SSD1322#16 from tekktrik/dev/send-bytes

Updating https://github.com/adafruit/Adafruit_CircuitPython_VL53L4CD to 1.0.1 from 1.0.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_VL53L4CD#2 from caternuson/typo_fix

Updating https://github.com/adafruit/Adafruit_CircuitPython_asyncio to 0.5.8 from 0.5.7:
  > Merge pull request adafruit/Adafruit_CircuitPython_asyncio#21 from FoamyGuy/display_button_example

Updating https://github.com/adafruit/Adafruit_CircuitPython_PortalBase to 1.11.3 from 1.11.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_PortalBase#67 from FoamyGuy/docs_fixes
  > Merge pull request adafruit/Adafruit_CircuitPython_PortalBase#66 from FoamyGuy/docs_fixes

Updating https://github.com/adafruit/Adafruit_CircuitPython_Requests to 1.11.0 from 1.10.7:
  > Merge pull request adafruit/Adafruit_CircuitPython_Requests#102 from dhalbert/cleanup
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.

5 participants