I’ve been ‘playing’ with my PRESTO, using the touch screen as input and the backlight Neopixels as output - basic colour mixing.
Working pretty well. Just need to report that the screen displays a little bit of jitter. Probably because all the cores are working flat out.
Here is the code if you would like to give it a go.
# PRESTO - Touch control of the Backlight Neopixels
# Tony Goodhew 4th Jan 2025
# Touch the + and - characters on the screen, or lower down,
# to change the current RGB values of the back lights
# Touch the Halt at top right to end execution of program
import time
from random import randint
from presto import Presto
import plasma # Needed for Neopixels
# Setup for the Presto display
presto = Presto(full_res=True)
display = presto.display
WIDTH, HEIGHT = display.get_bounds()
touch = presto.touch # Activate touch
# WS2812 / NeoPixel™ LEDs used for the backlight
bl = plasma.WS2812(7, 0, 0, 33)
bl.start()
for i in range(7):
bl.set_rgb(i, 255, 0, 0)
time.sleep(0.02)
# Create some colours
BLUE = display.create_pen(20,0,255)
WHITE = display.create_pen(255, 255, 255)
RED = display.create_pen(255,0,0)
ORANGE = display.create_pen(245, 165, 4)
GREEN = display.create_pen(0,255,0)
PINK = display.create_pen(250, 125, 180)
CYAN = display.create_pen(0,255,255)
MAGENTA = display.create_pen(255,0,255)
BLACK = display.create_pen(0, 0, 0)
YELLOW = display.create_pen(255, 255, 0)
GREY = display.create_pen(75, 75, 75)
display.set_font("bitmap8") # Change the font
# A few procedures to be used later
def clean(): # Clear the screen to Black
display.set_pen(BLACK)
display.clear()
def adjust(vt,dif,tmin,tmax): # Adjust RGB values
vt = vt + dif
if vt > tmax:
vt = tmax
elif vt < tmin:
vt = tmin
return vt
def sp(vv): # Simple right justification
vs = " " + str(vv)
vr =(vs[-3:])
return vr
def draw():
ss = [" -",sp(red)," +"," -",sp(green)," +"," -",sp(blue)," +"]
for p in range(9):
if p < 3:
display.set_pen(RED)
elif p < 6:
display.set_pen(GREEN)
else:
display.set_pen(BLUE)
pos = 15 + p * 50
display.text(ss[p],pos, 400,80,5)
# Title page
clean()
display.set_pen(RED)
display.text("Touch Inputs",40,120,460,8)
display.set_pen(YELLOW)
display.text("Colour control",90,280,480,4)
display.set_pen(BLUE)
display.text("Tony Goodhew, Leicester UK",120,450,480,2)
presto.update()
time.sleep(1)
# Neopixels off
for i in range(7):
bl.set_rgb(i,0, 0, 0)
time.sleep(0.02)
# Values: initial colour settings
red = 125
green = 125
blue = 125
d = 5 # Difference
running = True
while running:
clean()
draw()
display.set_pen(GREY)
display.text("Halt",400,20,100,3)
presto.update()
touch.poll()
if touch.state:
x = touch.x
y = touch.y
if y < 100 and x > 400:
running = False
if x <= 90:
red = adjust(red,-d,0,255)
elif x <= 165:
red = adjust(red, +d,0,255)
elif x <= 240:
green = adjust(green,-d,0,255)
elif x <= 315:
green = adjust(green,+d,0,255)
elif x <= 390:
blue = adjust(blue,-d,0,255)
elif x > 375:
blue = adjust(blue,+d,0,255)
for i in range(7):
bl.set_rgb(i,red, green,blue)
time.sleep(0.02)
# Tidy up
for i in range(7):
bl.set_rgb(i,0,0,0)
clean()
presto.update()
I’m not sure about the significance of the 33 in this statement. Does anyone know?
bl = plasma.WS2812(7, 0, 0, 33)
Comments/suggestions welcome.