Пример #1
0
import digitalio
import adafruit_stmpe610
from adafruit_rgb_display import ili9341, color565

# Create library object using our Bus SPI port
spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO)

# Adafruit Metro M0 + 2.8" Capacitive touch shield
cs_pin = digitalio.DigitalInOut(board.D9)
dc_pin = digitalio.DigitalInOut(board.D10)

# Initialize display
display = ili9341.ILI9341(spi, cs=cs_pin, dc=dc_pin)
# Fill with black!
display.fill(color565(0, 0, 0))

st_cs_pin = digitalio.DigitalInOut(board.D6)
st = adafruit_stmpe610.Adafruit_STMPE610_SPI(spi, st_cs_pin)

while True:
    if st.touched:
        while not st.buffer_empty:
            ts = st.touches
            for point in ts:
                # perform transformation to get into display coordinate system!
                y = point["y"]
                x = 4096 - point["x"]
                x = 2 * x // 30
                y = 8 * y // 90
                display.fill_rectangle(x - 2, y - 2, 4, 4, color565(255, 0, 0))
# Release any resources currently in use for the display
displayio.release_displays()

# Instantiate the 2.4" 320x240 TFT FeatherWing Display(#3315).
cs_pin = digitalio.DigitalInOut(board.D9)
dc_pin = digitalio.DigitalInOut(board.D10)
display = ili9341.ILI9341(board.SPI(), cs=cs_pin, dc=dc_pin)

# Fill the screen with black!
display.fill(color565(0, 0, 0))

# Instantiate the touchpad
ts_cs_pin = digitalio.DigitalInOut(board.D6)
ts = adafruit_stmpe610.Adafruit_STMPE610_SPI(
    board.SPI(),
    ts_cs_pin,
    calibration=((350, 3500), (350, 3500)),
    size=(display.width, display.height),
    disp_rotation=90,
    touch_flip=(True, True),
)

while True:
    point = ts.touch_point
    if point:
        # Display the touched point
        x = point[0]
        y = point[1]
        display.fill_rectangle(x - 2, y - 2, 4, 4, color565(255, 0, 0))
# Instantiate the 2.4" 320x240 TFT FeatherWing (#3315).
display = ILI9341(disp_bus, width=320, height=240)
_touch_flip = (False, False)
"""# Instantiate the 3.5" 480x320 TFT FeatherWing (#3651).
display = HX8357(disp_bus, width=480, height=320)
_touch_flip = (False, True)"""

# Always set rotation before instantiating the touchscreen
display.rotation = 0

# Instantiate touchscreen
ts_cs = digitalio.DigitalInOut(board.D6)
ts = adafruit_stmpe610.Adafruit_STMPE610_SPI(
    board.SPI(),
    ts_cs,
    calibration=((357, 3812), (390, 3555)),
    size=(display.width, display.height),
    disp_rotation=display.rotation,
    touch_flip=_touch_flip,
)

# Create the displayio group and show it
splash = displayio.Group()
display.show(splash)

# Defiine the button
button = Button(
    x=BUTTON_X,
    y=BUTTON_Y,
    width=BUTTON_WIDTH,
    height=BUTTON_HEIGHT,
    style=BUTTON_STYLE,
Пример #4
0
# SPDX-FileCopyrightText: 2022 CedarGroveMakerStudios for Adafruit Industries
# SPDX-License-Identifier: MIT
"""
Simple print-to-REPL demo using the STMPE610 resistive touch controller.
"""

import board
import digitalio
import adafruit_stmpe610

# Instantiate the touchpad
ts_cs_pin = digitalio.DigitalInOut(board.D6)
ts = adafruit_stmpe610.Adafruit_STMPE610_SPI(board.SPI(), ts_cs_pin)

print("Go Ahead - Touch the Screen - Make My Day!")
print("(x, y, pressure)")
while True:
    point = ts.touch_point
    if point:
        print(point)
else:
    print("Warning: invalid rotation value -- defalting to zero")
    display.rotation = 0
    time.sleep(1)

# Activate the display graphics unless REPL_ONLY=True.
if not REPL_ONLY:
    display_group = displayio.Group()
    display.show(display_group)

# Instantiate touchscreen.
ts_cs = digitalio.DigitalInOut(board.D6)
if RAW_DATA:
    # Display raw touchscreen values; calibration tuple not required.
    ts = adafruit_stmpe610.Adafruit_STMPE610_SPI(
        board.SPI(), ts_cs, disp_rotation=display.rotation, touch_flip=_touch_flip
    )
else:
    # Display calibrated screen coordinates.
    # Update the raw calibration tuple with previously measured values.
    ts = adafruit_stmpe610.Adafruit_STMPE610_SPI(
        board.SPI(),
        ts_cs,
        calibration=CALIBRATION,
        size=(display.width, display.height),
        disp_rotation=display.rotation,
        touch_flip=_touch_flip,
    )

# Define the graphic objects if REPL_ONLY = False.
if not REPL_ONLY: