These is the main loop. It is timed by the clock to execute at one-second intervals.
Each time the current is measured and the values accumulated. When there sufficient accumulation, an increment is subtracted which measures an element of charge. There are two selectable shunts, 5.1 ohms and 0.85 ohms. The increments are 1 and 5 milliampere-second respectively. These are also counted.
Each time there is a movement a record is sent to the SD Writer. A delay of nearly one second is forced between opening the file and writing to it, because this can take considerable time. The record contains current, voltage, and count, separated by commas.