From 5d2cb43fc8619ba9a0afaa6351739fb6bee36d92 Mon Sep 17 00:00:00 2001 From: DJDevon3 <49322231+DJDevon3@users.noreply.github.com> Date: Mon, 22 Jan 2024 09:44:59 -0500 Subject: [PATCH 1/4] add sprite_button example for TFT Featherwing simple menu button demo specifically for TFT featherwing touch display --- ...prite_button_tft_featherwing_simpletest.py | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 examples/sprite_button_tft_featherwing_simpletest.py diff --git a/examples/sprite_button_tft_featherwing_simpletest.py b/examples/sprite_button_tft_featherwing_simpletest.py new file mode 100644 index 0000000..ed25edf --- /dev/null +++ b/examples/sprite_button_tft_featherwing_simpletest.py @@ -0,0 +1,73 @@ +import displayio +import terminalio +import board +import digitalio +import time +from adafruit_hx8357 import HX8357 # TFT Featherwing display driver +import adafruit_stmpe610 # TFT Featherwing V1 touch driver +from adafruit_display_text import label +from adafruit_bitmap_font import bitmap_font +from adafruit_button.sprite_button import SpriteButton + +# 3.5" TFT Featherwing is 480x320 +displayio.release_displays() +DISPLAY_WIDTH = 480 +DISPLAY_HEIGHT = 320 + +# Initialize TFT Display +spi = board.SPI() +tft_cs = board.D9 +tft_dc = board.D10 +display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs) +display = HX8357(display_bus, width=DISPLAY_WIDTH, height=DISPLAY_HEIGHT) +display.rotation = 0 +_touch_flip = (False, True) + +# Initialize 3.5" TFT Featherwing Touchscreen +ts_cs_pin = digitalio.DigitalInOut(board.D6) +touchscreen = adafruit_stmpe610.Adafruit_STMPE610_SPI( + board.SPI(), + ts_cs_pin, + calibration=((231, 3703), (287, 3787)), + size=(display.width, display.height), + disp_rotation=display.rotation, + touch_flip=_touch_flip, +) + +TEXT_WHITE = 0xFFFFFF + +# --| Button Config |-- +BUTTON_WIDTH = 7 * 16 +BUTTON_HEIGHT = 2 * 16 +BUTTON_MARGIN = 5 + +# Defiine the button +button = SpriteButton( + x=BUTTON_MARGIN, + y=BUTTON_MARGIN, + width=BUTTON_WIDTH, + height=BUTTON_HEIGHT, + label="MENU", + label_font=terminalio.FONT, + label_color=TEXT_WHITE, + bmp_path="icons/gradient_button_0.bmp", + selected_bmp_path="icons/gradient_button_1.bmp", + transparent_index=0, +) + +main_group = displayio.Group() +main_group.append(button) +display.root_group = main_group + +while True: + p = touchscreen.touch_point + if p: + if button.contains(p): + if not button.selected: + button.selected = True + time.sleep(0.25) # Wait a bit so we can see the button color change + print("Button Pressed") + else: + button.selected = False # When touch moves outside of button + else: + button.selected = False # When button is released \ No newline at end of file From 6c1d2bed719ebbf2a428fae7266e1c700c54d215 Mon Sep 17 00:00:00 2001 From: DJDevon3 <49322231+DJDevon3@users.noreply.github.com> Date: Mon, 22 Jan 2024 09:53:31 -0500 Subject: [PATCH 2/4] make pylint happy --- examples/sprite_button_tft_featherwing_simpletest.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/examples/sprite_button_tft_featherwing_simpletest.py b/examples/sprite_button_tft_featherwing_simpletest.py index ed25edf..f30e63e 100644 --- a/examples/sprite_button_tft_featherwing_simpletest.py +++ b/examples/sprite_button_tft_featherwing_simpletest.py @@ -1,12 +1,10 @@ +import time import displayio import terminalio import board import digitalio -import time from adafruit_hx8357 import HX8357 # TFT Featherwing display driver import adafruit_stmpe610 # TFT Featherwing V1 touch driver -from adafruit_display_text import label -from adafruit_bitmap_font import bitmap_font from adafruit_button.sprite_button import SpriteButton # 3.5" TFT Featherwing is 480x320 @@ -65,9 +63,9 @@ if button.contains(p): if not button.selected: button.selected = True - time.sleep(0.25) # Wait a bit so we can see the button color change + time.sleep(0.25) # Wait a bit so we can see the button color change print("Button Pressed") else: button.selected = False # When touch moves outside of button else: - button.selected = False # When button is released \ No newline at end of file + button.selected = False # When button is released From bce89bfeb29e68a2d5ab9e0e852e838adbbeab47 Mon Sep 17 00:00:00 2001 From: DJDevon3 <49322231+DJDevon3@users.noreply.github.com> Date: Mon, 22 Jan 2024 09:57:16 -0500 Subject: [PATCH 3/4] included header copyright --- examples/sprite_button_tft_featherwing_simpletest.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/sprite_button_tft_featherwing_simpletest.py b/examples/sprite_button_tft_featherwing_simpletest.py index f30e63e..dab7675 100644 --- a/examples/sprite_button_tft_featherwing_simpletest.py +++ b/examples/sprite_button_tft_featherwing_simpletest.py @@ -1,3 +1,5 @@ +# SPDX-FileCopyrightText: 2024 DJDevon3 +# SPDX-License-Identifier: MIT import time import displayio import terminalio From 5cf970e7c16857317f6877f9aab9a16e32005708 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sun, 28 Jan 2024 17:56:44 -0600 Subject: [PATCH 4/4] rename, use bmps dir for paths --- ...display_button_spritebutton_tft_featherwing_simpletest.py} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename examples/{sprite_button_tft_featherwing_simpletest.py => display_button_spritebutton_tft_featherwing_simpletest.py} (95%) diff --git a/examples/sprite_button_tft_featherwing_simpletest.py b/examples/display_button_spritebutton_tft_featherwing_simpletest.py similarity index 95% rename from examples/sprite_button_tft_featherwing_simpletest.py rename to examples/display_button_spritebutton_tft_featherwing_simpletest.py index dab7675..bac2cf7 100644 --- a/examples/sprite_button_tft_featherwing_simpletest.py +++ b/examples/display_button_spritebutton_tft_featherwing_simpletest.py @@ -50,8 +50,8 @@ label="MENU", label_font=terminalio.FONT, label_color=TEXT_WHITE, - bmp_path="icons/gradient_button_0.bmp", - selected_bmp_path="icons/gradient_button_1.bmp", + bmp_path="bmps/gradient_button_0.bmp", + selected_bmp_path="bmps/gradient_button_1.bmp", transparent_index=0, )