Bird
0
0

You want to continuously display live temperature readings from a sensor on an OLED screen using Python. Which approach correctly updates the display every second without flickering?

hard🚀 Application Q15 of 15
Raspberry Pi - Display and Output
You want to continuously display live temperature readings from a sensor on an OLED screen using Python. Which approach correctly updates the display every second without flickering?
import time
while True:
    temp = read_sensor()
    image = Image.new('1', (disp.width, disp.height))
    draw = ImageDraw.Draw(image)
    draw.text((0, 0), f'Temp: {temp}C', font=font, fill=255)
    disp.image(image)
    disp.display()
    time.sleep(1)

What is the best improvement to reduce flicker?
AClear the display before drawing each new image
BCreate the image and draw objects once outside the loop and reuse them
CRemove time.sleep(1) to update faster
DUse disp.clear() after disp.display() inside the loop
Step-by-Step Solution
Solution:
  1. Step 1: Understand flicker cause

    Creating new image and draw objects each loop causes flicker due to redraw overhead.
  2. Step 2: Optimize by reusing objects

    Creating image and draw once outside loop and clearing draw area inside loop reduces flicker.
  3. Final Answer:

    Create the image and draw objects once outside the loop and reuse them -> Option B
  4. Quick Check:

    Reuse image/draw objects to reduce flicker [OK]
Quick Trick: Create image/draw once outside loop to avoid flicker [OK]
Common Mistakes:
MISTAKES
  • Recreating image each loop causing flicker
  • Removing sleep causing too fast updates
  • Calling disp.clear() after display has no effect

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes