Simple test

Ensure your device works with this simple test.

examples/displayio_flipinput_simpletest.py
  1# SPDX-FileCopyrightText: 2021 Kevin Matocha
  2#
  3# SPDX-License-Identifier: MIT
  4#############################
  5"""
  6This is a basic demonstration of a FlipInput widget.
  7"""
  8
  9# pylint: disable=invalid-name
 10
 11import time
 12import board
 13import displayio
 14import adafruit_touchscreen
 15from adafruit_bitmap_font import bitmap_font
 16from displayio_flipinput import FlipInput
 17
 18display = board.DISPLAY  # create the display on the PyPortal,
 19# otherwise change this to setup the display
 20# for display chip driver and pinout you have (e.g. ILI9341)
 21
 22# setup the touchscreen
 23ts = adafruit_touchscreen.Touchscreen(
 24    board.TOUCH_XL,
 25    board.TOUCH_XR,
 26    board.TOUCH_YD,
 27    board.TOUCH_YU,
 28    calibration=((5200, 59000), (5800, 57000)),
 29    size=(display.width, display.height),
 30)
 31
 32# Select the font file for use
 33font_file = "fonts/DSEG14Classic-Regular-64-ModS.pcf"
 34my_font = bitmap_font.load_font(font_file)
 35
 36my_flip1 = FlipInput(
 37    display,
 38    anchor_point=[0.0, 0.0],
 39    anchored_position=[50, 40],
 40    color=0xFF2222,  # reddish orange color
 41    value_list=[  # list of month strings, using three characters
 42        "JAN",
 43        "FEB",
 44        "MAR",
 45        "APR",
 46        "MAY",
 47        "JUN",
 48        "JUL",
 49        "AUG",
 50        "SEP",
 51        "OCT",
 52        "NOV",
 53        "DEC",
 54    ],
 55    font_scale=5,
 56    horizontal=False,  # use vertical arrows
 57    animation_time=0.4,
 58)
 59
 60my_flip2 = FlipInput(
 61    display,
 62    anchor_point=[0.0, 0.0],
 63    anchored_position=[220, 40],
 64    color=0xFF2222,  # reddish orange color
 65    value_list=["{0:02d}".format(x) for x in range(1, 31 + 1)],
 66    # use a list of strings from 01 through 31
 67    # use the {0:02d} format string to always use two digits (e.g. '03')
 68    font_scale=5,
 69    horizontal=False,  # use vertical arrows
 70    animation_time=0.4,
 71)
 72
 73my_flip3 = FlipInput(
 74    display,
 75    anchor_point=[0.5, 1.0],
 76    anchored_position=[320 // 2, 240 - 10],
 77    color=0xFF2222,  # reddish orange color
 78    value_list=["{}".format(x) for x in range(1985, 2022, 1)],
 79    # use a list with values of stringsfrom 1985 to 2022
 80    font=my_font,
 81    horizontal=True,  # use horizontal arrows
 82    animation_time=0.8,  # add more time since the animation covers a longer distance
 83)
 84
 85# Pick an interesting date to start
 86#
 87# You can set the value by direct integer indexes of the list or by a string
 88# Here are three ways to set the values:
 89my_flip1.value = 9  # use direct integer indexing to set the value to the 10th month
 90my_flip2.value = my_flip2.value_list.index("21")  # find the index yourself by
 91# searching the value_list
 92my_flip3.value = "2015"  # or set the value based on a string that is in the value_list
 93
 94# Create the group to display and append the FlipInput widgets
 95my_group = displayio.Group()
 96my_group.append(my_flip1)
 97my_group.append(my_flip2)
 98my_group.append(my_flip3)
 99
100display.show(my_group)  # add high level Group to the display
101display.auto_refresh = True
102
103while True:
104
105    p = ts.touch_point
106    # print("touch_point p: {}".format(p)) # print the touch point
107
108    if p:  # if touched, check if any of the widgets was triggered
109        if my_flip1.contains(p):
110            my_flip1.selected(p)
111            time.sleep(0.15)  # add a short delay to reduce accidental press
112        elif my_flip2.contains(p):
113            my_flip2.selected(p)
114            time.sleep(0.15)  # add a short delay to reduce accidental press
115        elif my_flip3.contains(p):
116            my_flip3.selected(p)
117            time.sleep(0.15)  # add a short delay to reduce accidental press
118
119    time.sleep(0.01)  # small delay seems to improve touch response