PRESTO Slide Potentiometer

This was easier than I thought it would be.

You can find a video here: https://youtu.be/aEbSWqXsWD0

Here is the code:

# PRESTO Touch Slider Potentiometer
# Tony Goodhew 1 Jan 2025

import time
from random import randint
from presto import Presto

# Setup for the Presto display
presto = Presto(full_res=True,ambient_light=True)
display = presto.display

WIDTH, HEIGHT = display.get_bounds()

# Couple of colours for use later
LBLUE = 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)
BLUE = display.create_pen(0,0,255)
GREY = display.create_pen(90,90,90)

COLOURS = [BLUE, RED, ORANGE, GREEN, PINK, PURPLE]

touch = presto.touch

display.set_font("bitmap8")


def draw_slider(xx,yy,v,col):
    display.set_pen(BLACK)
    display.rectangle(xx+260,yy+1,100,50)
    display.set_pen(WHITE)
    if v < xx: v = xx
    if v > xx + 255: v = xx + 255
    display.rectangle(xx,yy,257,52)
    display.set_pen(BLACK)
    display.rectangle(xx+260,yy+1,100,50)
    display.set_pen(col)
    display.rectangle(xx+1,yy+1,v-xx,50)
    display.text(str(v-xx), xx+270,yy + 8, 100,3)
    presto.update()

display.set_pen(BLACK)
display.clear()
presto.update()

display.set_pen(RED)
display.text("Touch Slider",40,100,460,8)
display.set_pen(BLUE)
display.text("Tony Goodhew, Leicester UK",120,450,480,2)
display.set_pen(GREY)
display.text("Halt",390,30,100,3)
draw_slider(100,300, 177,LBLUE)

running = True
while running:
    txt=""
    touch.poll()
    if touch.state:
        x = touch.x
        y = touch.y
        if (y > 300) and (y < 350):
#        print(x,y) # Used for testing 
            draw_slider(100,300, x,LBLUE)
        if ( y < 100) and (x > 350):
            running = False

display.set_pen(BLACK)
display.clear()
presto.update()
3 Likes