Need help to combine two different task using LED matrix

Totally 3 8x8 panels will be used. 1 panel for task1 and the remaining panels for task2.

Task1: If I vary the ultrasonic range from 0 to 400cm, LED matrix will start to light up from row 0 to row 7
ultrasonicwithLEDmatrix-WokwiESP32STM32ArduinoSimulator2-ezgif.com-video-to-gif-converter

Task2: Using Potentiometer
Value range from 512 to 0 - panel 1 will glow like row 0 to row 7
Value range from 512 to 1024 - panel 2, row 0 to row 7
ledmatrix-WokwiESP32STM32ArduinoSimulator2-ezgif.com-video-to-gif-converter

Hope I explained in detail.