I have this code below for turning On 6 led (like led bar) regarding the reading value from a High power LED driver board
#define F_CPU 16000000UL // Assuming a 16 MHz clock if using ATmega32A (adjust if different)

#include <avr/io.h>
#include <util/delay.h>

// Define potentiometer ADC channel (PA0 = ADC0)
#define potPin 0

// Define digital I/O pins for LEDs
#define led1 PD4
#define led2 PD5
#define led3 PD6
#define led4 PD7
#define led5 PB0
#define led6 PB1

void adc_init()
{
    // Initialize ADC
    ADMUX = (1<<REFS0); // Select AVcc as reference voltage and ADC0 as input channel
    ADCSRA = (1<<ADEN) | (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0); // Enable ADC and set prescaler to 128
}

uint16_t adc_read(uint8_t ch)
{
    // Select ADC channel with safety mask and without changing the reference voltage selection
    ADMUX = (ADMUX & 0xF0) | (ch & 0x0F);

    // Start single conversion
    ADCSRA |= (1<<ADSC);

    // Wait until conversion is complete
    while (ADCSRA & (1<<ADSC));

    return ADC;
}

int main(void)
{
    // Set up the LED pins as output
    DDRD |= (1<<led1) | (1<<led2) | (1<<led3) | (1<<led4);
    DDRB |= (1<<led5) | (1<<led6);
    
    // Initialize ADC
    adc_init();

    while(1)
    {
        // Read the value from the potentiometer
        uint16_t potValue = adc_read(potPin);

        // Map the potentiometer value from (65 - 337) to (0 - 1023)
        // Adjust this mapping to your application needs
        uint16_t mappedValue = (uint32_t)(potValue - 65) * 1023 / (337 - 65);

        // Create additional thresholds for 6 LEDs
        uint16_t threshold1 = 170; // First threshold
        uint16_t threshold2 = 341; // Second threshold
        uint16_t threshold3 = 512; // Midpoint
        uint16_t threshold4 = 683; // Fourth threshold
        uint16_t threshold5 = 854; // Fifth threshold

        // Turn off all LEDs to start
        PORTD &= ~((1<<led1) | (1<<led2) | (1<<led3) | (1<<led4));
        PORTB &= ~((1<<led5) | (1<<led6));

        // Determine which LEDs to light up based on the mappedValue
        if (mappedValue >= threshold5) {
            // In the highest range, light up all six LEDs
            PORTD |= (1<<led1) | (1<<led2) | (1<<led3) | (1<<led4);
            PORTB |= (1<<led5) | (1<<led6);
        } else if (mappedValue >= threshold4) {
            // Light up five LEDs
            PORTD |= (1<<led1) | (1<<led2) | (1<<led3) | (1<<led4);
            PORTB |= (1<<led5);
        } else if (mappedValue >= threshold3) {
            // Light up four LEDs
            PORTD |= (1<<led1) | (1<<led2) | (1<<led3) | (1<<led4);
        } else if (mappedValue >= threshold2) {
            // Light up three LEDs
            PORTD |= (1<<led1) | (1<<led2) | (1<<led3);
        } else if (mappedValue >= threshold1) {
            // Light up two LEDs
            PORTD |= (1<<led1) | (1<<led2);
        } else if (mappedValue > 0) {
            // Light up one LED
            PORTD |= (1<<led1);
        }

        // Small delay to reduce flickering
        _delay_ms(100);
    }
}

but there are some problems; first of all the LEDs are turned on and all of them blink when my potentiometer is at minimum and after turning a little bit of potentiometer the first led is turn on and we don't have any blinking , what could be problem ?