Can you access FrameBuffer in Pimoroni PicoGraphics Micropython W

Here is a pure Pimoroni Graphics version with a little help with the syntax. This is running on the Pico Explorer board (240x240 pixels) and includes input from a 10 K Ohm potentiometer on ADC(0).

Speed does not appear to be a problem and it is flicker free.

# Analogue Dial on a Pimoroni Pico Explorer with Pico Graphics
# 10 K Ohm potentiometer on ADC(0) = GP26
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)

potentiometer = machine.ADC(26) # Install potentiometer


# Basics demo - Instruction crib sheet for Copy and Paste
# If you are new to Pimoroni Graphics instructions
display.set_pen(red)
w,h = display.get_bounds()
display.rectangle(0,0,w,h)
display.update()
display.set_font("bitmap8") 
display.set_pen(white)
#display.text(text, x, y, wordwrap, scale, angle, spacing)
display.text("Tony",20,20,219,4)

display.set_pen(blue)
display.text("Hello World", 70, 60, scale=2)
display.line(0,70,239,239)
display.circle(50, 190, 50)

display.set_pen(green)
display.rectangle(20,190,30,40)
display.triangle(140, 130,150,200,200,140)
display.set_pen(black)
display.pixel(30,200)

display.update()
time.sleep(2)

# =========== Main Program ================
display.clear()
xc = 120
yc = 120
display.set_pen(blue)
display.circle(xc,yc,100)
r = 103                                      # Tick outer radius
for p in range(0,101,10):                    # White Ticks at 10 % intervals
    theta = p * 1.8                          # Angle above horizontal in degrees
    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
display.set_pen(black)
display.circle(xc,yc,75)           # Overwrite inner tick lines
display.rectangle(0,yc+1,240,120)
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 * 1.8
    display.set_pen(black)
    display.line(120,120,120+old_xn,120+old_yn) # Overwrite the old hand
    display.rectangle(0,121,240,120)            # Clear text area
    display.set_pen(green)
    display.text("Tony Goodhew",20,210,scale=3)
    theta_rad = math.radians(theta)
    theta_rad = math.radians(theta)
    display.set_pen(white)
    display.text(str(p) +" %",100,130,scale=3)  # Percentage value as text
    yn = -int(r * math.sin(theta_rad))
    xn = -int(r * math.cos(theta_rad))
    display.set_pen(red)
    display.line(120,120,120+xn,120+yn)         # Draw the new hand
    display.update()                            # Update screen
    time.sleep(0.1)                             # Delay
    old_xn = xn                                 # Store current hand end corordinates
    old_yn = yn                                 #  for overwriting in next loop pass
    
display.update()

# Random values
for c in range(25):
    p = random.randint(0,100)
    theta = p * 1.8
    display.set_pen(black)
    display.line(120,120,120+old_xn,120+old_yn) # Overwrite the old hand
    display.rectangle(0,121,240,120)            # Clear text area
    display.set_pen(red)
    display.text("Tony Goodhew",20,210,scale=3)
    theta_rad = math.radians(theta)
    display.set_pen(white)
    display.text(str(p) +" %",100,130,scale=3)  # Percentage value as text
    yn = -int(r * math.sin(theta_rad))
    xn = -int(r * math.cos(theta_rad))
    display.set_pen(red)
    display.line(120,120,120+xn,120+yn)         # Draw the new hand
    display.update()                            # Update screen
    time.sleep(0.1)                             # Delay
    old_xn = xn                                 # Store current hand end corordinates
    old_yn = yn                                 #  for overwriting in next loop pass
    
display.update()

# Potentiometer Control on ADC(0) 
for c in range(100):
    pot = potentiometer.read_u16()/256
    pot = int(pot * 256.0 /255.0) - 1
    pot = int(pot *100 / 255)
    if pot > 100:
        pot = 100
    p = pot
    theta = p * 1.8
    display.set_pen(black)
    display.line(120,120,120+old_xn,120+old_yn) # Overwrite the old hand
    display.rectangle(0,121,240,80)            # Clear text area
    display.set_pen(yellow)
    display.text("Tony Goodhew",20,210,scale=3)
    theta_rad = math.radians(theta)
    theta_rad = math.radians(theta)
    display.set_pen(white)
    display.text(str(p) +" %",100,130,scale=3)  # Percentage value as text
    yn = -int(r * math.sin(theta_rad))
    xn = -int(r * math.cos(theta_rad))
    display.set_pen(red)
    display.line(120,120,120+xn,120+yn)         # Draw the new hand
    display.update()                            # Update screen
    time.sleep(0.1)                             # Delay
    old_xn = xn                                 # Store current hand end corordinates
    old_yn = yn                                 #  for overwriting in next loop pass
    time.sleep(.1)

# Tidy up
display.set_pen(black)
display.clear()
display.update()

UF2 used was from here:

The third from the top.

Much easier than we first thought! Hope this helps.

2 Likes