This version has the needle passing over the numbers inside the ring. These numbers are re-drawn in each loop but the whole screen updates so quickly that you do not notice. Just not sure how quickly a file screen can be re-drawn.
# Analogue MPH Dial on a Pimoroni Pico Explorer with Pico Graphics
# Tony Goodhew 6 Jan 2023
from picographics import PicoGraphics, DISPLAY_LCD_240X240
import math
import time
import random
import machine # for ADC pot
display = PicoGraphics(display=DISPLAY_LCD_240X240)
red = display.create_pen(255,0,0)
white = display.create_pen(255,255,255)
green = display.create_pen(0,255,0)
blue = display.create_pen(0,0,255)
black = display.create_pen(0,0,0)
yellow = display.create_pen(255,255,0)
# =========== Main Program ================
display.set_font("bitmap8") # Provides Lower Case letters
display.set_pen(black)
display.clear()
# Numbers Outside Ring
xc = 120
yc = 120
display.set_pen(blue)
display.circle(xc,yc,85)
r = 90 # Tick outer radius
for p in range(0,101,10): # White Ticks at 10 % intervals
theta = p * 2.7 -45
theta_rad = math.radians(theta) # Angle in radians
yn = -int(r * math.sin(theta_rad)) # Calculate outer tick coordinates
xn = -int(r * math.cos(theta_rad))
display.set_pen(white)
display.line(120,120,120+xn,120+yn) # Draw the tick from centre
r = 85 # Tick outer radius
for p in range(0,101,5):
theta = p * 2.7 -45
theta_rad = math.radians(theta) # Angle in radians
yn = -int(r * math.sin(theta_rad)) # Calculate outer tick coordinates
xn = -int(r * math.cos(theta_rad))
display.set_pen(white)
display.line(120,120,120+xn,120+yn)
display.set_pen(black)
display.circle(xc,yc,75) # Overwrite inner tick lines
d=r
display.triangle(xc,yc,xc+d-1,yc+d,xc-d,yc+d)
display.set_pen(white)
display.text("0",45,185,scale=2)
display.text("100",185,185,scale=2)
display.text("10",14,140,scale=2)
display.text("90",210,140,scale=2)
display.text("20",12,98,scale=2)
display.text("80",212,98,scale=2)
display.text("30",23,55,scale=2)
display.text("70",200,55,scale=2)
display.text("40",65,24,scale=2)
display.text("60",155,24,scale=2)
display.text("50",110,9,scale=2)
display.update()
# Counting up in fives
r = 74 # Length of hand
old_xn = 0
old_yn = 0
for p in range(0,101,5): # Percentages at 5 % interval
theta = p * 2.7 -45
display.set_pen(black)
display.line(120,120,120+old_xn,120+old_yn) # Overwrite the old hand
display.rectangle(50,200,100,25) # Clear text area
theta_rad = math.radians(theta)
theta_rad = math.radians(theta)
display.set_pen(yellow)
ts =" " + str(p)
display.text(ts[-3:],100,200,scale=3) # Percentage value as text
yn = -int(r * math.sin(theta_rad))
xn = -int(r * math.cos(theta_rad))
display.set_pen(black)
display.circle(xc,yc,75) # Clear centre
display.set_pen(white)
display.text("MPH",100,80,scale=3)
display.set_pen(red)
xnsm = int(xn/10)
ynsm = int(yn/10)
display.triangle(120+xn, 120+yn, 120+ynsm, 120-xnsm, 120-ynsm, 120+xnsm)
display.circle(xc,yc,6)
display.update() # Update screen
time.sleep(0.2) # Delay
old_xn = xn # Store current hand end corordinates
old_yn = yn # for overwriting in next loop pass
display.update()
# Numbers Inside Ring
display.set_pen(black)
display.clear()
xc = 120
yc = 120
display.set_pen(blue)
display.circle(xc,yc,116)
r = 118
# Tick outer radius
for p in range(0,101,5):
theta = p * 2.7 -45
theta_rad = math.radians(theta) # Angle in radians
yn = -int(r * math.sin(theta_rad)) # Calculate outer tick coordinates
xn = -int(r * math.cos(theta_rad))
display.set_pen(white)
display.line(120,120,120+xn,120+yn)
display.set_pen(black)
display.circle(xc,yc,100) # Overwrite inner tick lines
d=r
display.triangle(xc,yc,xc+d-1,yc+d,xc-d,yc+d)
display.set_pen(white)
#display.update()
# Counting up in fives
r = 90 # Length of hand
old_xn = 0
old_yn = 0
for p in range(0,101,1): # Interval of 1 degree
theta = p * 2.7 -45
display.set_pen(black)
display.line(120,120,120+old_xn,120+old_yn) # Overwrite the old hand
display.rectangle(50,200,100,25) # Clear text area
theta_rad = math.radians(theta)
theta_rad = math.radians(theta)
yn = -int(r * math.sin(theta_rad))
xn = -int(r * math.cos(theta_rad))
display.set_pen(black)
display.circle(xc,yc,90) # Clear centre
display.set_pen(green)
display.text("°F",100,80,scale=3)
display.text("0",60,185,scale=2)
display.text("100",160,185,scale=2)
display.text("10",30,140,scale=2)
display.text("90",195,140,scale=2)
display.text("20",24,98,scale=2)
display.text("80",198,98,scale=2)
display.text("30",43,58,scale=2)
display.text("70",180,58,scale=2)
display.text("40",70,35,scale=2)
display.text("60",153,35,scale=2)
display.text("50",110,25,scale=2)
display.set_pen(red)
xnsm = int(xn/10)
ynsm = int(yn/10)
display.triangle(120+xn, 120+yn, 120+ynsm, 120-xnsm, 120-ynsm, 120+xnsm)
display.circle(xc,yc,6)
# display.update() # Update screen
time.sleep(0.2) # Delay
old_xn = xn # Store current hand end corordinates
old_yn = yn # for overwriting in next loop pass
display.set_pen(yellow)
ts =" " + str(p)
display.text(ts[-3:],100,200,scale=3) # Percentage value as text
display.update()
time.sleep(0.2)
Have fun.