You can use Blockly to create a program that continuously reads the distance measured by the ultrasonic sensor and calculates the average distance over a specific time period. You can use variables to store the sum of distances and a counter variable to keep track of the number of measurements. With Blockly’s math blocks, you can perform the necessary calculations and display the average distance.