CircuitPython neopixel flicker with for loop

https://www.codecademy.com/courses/learn-circuitpython/projects/circuit-playground-plant-care?action=resume_content_item

I’ve done this course, and I’m trying to show the moisture level with the neo pixels. I’ve sort of figured it out, but the led’s flicker a lot when the moisture is high. It seems like the for loop is the issue here, it flickers even if I change out moist_level with 10, and flickers less if I input a lower number. Is there an easy fix for this?

The sleep command does not affect the flicker other than slowing it a bit.

Here’s my code:

from adafruit_circuitplayground.express import cpx
from time import sleep
import touchio
import board


touch = touchio.TouchIn(board.A1)

def translate(value, value_min, value_max, out_min, out_max): 
    value_range = value_max - value_min
    out_range = out_max - out_min
    value_scaled = float(value - value_min) / float(value_range)
    
    return out_min + (value_scaled * out_range)


while True:
    moisture = touch.raw_value
    moist_level = int(round(translate(moisture, 1500, 4064, 0, 9)))
    
    if cpx.switch:
        if cpx.button_a:
            print("Temperature: ", cpx.temperature)
        if cpx.button_b:
            print("Light: ", cpx.light)
    else:
        print((moisture, moist_level))
    
    cpx.pixels.fill((30, 0, 0))
    for x in range(moist_level):
        cpx.pixels[x] = (0, 30, 0)
    
    sleep(0.1)