Delighted with my Presto. Here is another demo to help get you started.
Merry Christmas to you all!
# Touch screen demo on PRESTO
# Tony Goodhew 25 Dec 2024
import time
from random import randint
from presto import Presto
# Setup for the Presto display
presto = Presto(ambient_light=True)
display = presto.display
WIDTH, HEIGHT = display.get_bounds()
# Couple of colours for use later
BLUE = display.create_pen(28, 181, 202)
WHITE = display.create_pen(255, 255, 255)
RED = display.create_pen(230, 60, 45)
ORANGE = display.create_pen(245, 165, 4)
GREEN = display.create_pen(9, 185, 120)
PINK = display.create_pen(250, 125, 180)
PURPLE = display.create_pen(118, 95, 210)
BLACK = display.create_pen(0, 0, 0)
COLOURS = [BLUE, RED, ORANGE, GREEN, PINK, PURPLE]
display.clear()
touch = presto.touch
# (xx, yy) point of arrowhead sz is size = point to centre of base
xx= 185
yy= 185
sz = 25
sz2 = int(sz*0.8)
s2 = int(sz*0.5773) # tan30
d = 2 * sz
def wipe():
display.set_pen(BLACK)
display.rectangle(0,0,100,50)
display.set_pen(RED)
display.triangle(xx,yy-d,xx-s2,yy-d+sz, xx+s2,yy-d+sz)
display.triangle(xx,yy+d,xx-s2,yy+d-sz,xx+s2,yy+d-sz)
display.triangle(xx+d,yy,xx+sz,yy-s2,xx+sz,yy+s2)
display.triangle(xx-d,yy,xx-sz,yy+s2,xx-sz,yy-s2)
display.set_pen(GREEN)
display.circle(xx,yy,s2)
# Grid lines
display.set_pen(BLUE)
display.line(xx-d,yy-d,xx+d,yy-d)
display.line(xx-d,yy-sz2,xx+d,yy-sz2)
display.line(xx-d,yy+d,xx+d,yy+d)
display.line(xx-d,yy+sz2,xx+d,yy+sz2)
display.line(xx-d,yy-d,xx-d,yy+d)
display.line(xx-sz2,yy-d,xx-sz2,yy+d)
display.line(xx+sz2,yy-d,xx+sz2,yy+d)
display.line(xx+d,yy-d,xx+d,yy+d)
presto.update()
while True:
txt=""
touch.poll()
if touch.state:
x = touch.x
y = touch.y
print(x,y)
display.set_pen(BLUE)
if (x > (xx-d)) and (x <= (xx - sz2)) and (y > (yy -d)) and (y <= (yy -sz2)): # top left
txt = "NW"
if (x > (xx-d)) and (x <= (xx - sz2)) and (y > (yy -sz2)) and (y <= (yy +sz2)): # centre left
txt = "W"
if (x > (xx-d)) and (x <= (xx - sz2)) and (y > (yy +sz2)) and (y <= (yy +d)): # bottom left
txt = "SW"
if (x > (xx-sz2)) and (x <= (xx + sz2)) and (y > (yy -d)) and (y <= (yy -sz2)): # top centre
txt = "N"
if (x > (xx-sz2)) and (x <= (xx + sz2)) and (y > (yy -sz2)) and (y <= (yy +sz2)): #centre,centre
txt = "C"
if (x > (xx-sz2)) and (x <= (xx + sz2)) and (y > (yy +sz2)) and (y <= (yy +d)): # bottom centre
txt ="S"
if (x > (xx+sz2)) and (x <= (xx + d)) and (y > (yy -d)) and (y <= (yy -sz2)): # top right
txt = "NE"
if (x > (xx+sz2)) and (x <= (xx + d)) and (y > (yy -sz2)) and (y <= (yy +sz2)): # centre right
txt ="E"
if (x > (xx+sz2)) and (x < (xx + d)) and (y > (yy +sz2)) and (y < (yy +d)): # bottom right
txt = "SE"
wipe()
display.set_pen(BLUE)
display.text(txt,0,0,200,5)
presto.update()
time.sleep(0.1)
Try changing the value of sz, xx and yy. The grid can be moved and resized.
Just a thought: Why is it presto.update() and not display.update() ?
I wrote this because I get an error when trying to run the touch_buttons program.
Iโm really impressed with the accuracy of the touch co-ordinates.
Comments welcome.