Reading from a CT Sensor pin affected by Seven Segment Displays switching on and off

I’m not sure that your algorithm here, which appears to be a “peak detection” type, is really suitable for this application. It will be very prone to spurious spike effects. Maybe you should look at an algorithm which uses a current transformer For energy measurement type applications. These will continually integrate samples with respect to time and should deliver a much more stable result of the power provided to the device (circular saw etc.).

Here is one library which may be useful:

EDIT

Can't you get a complete sine wave like say in this picture (taken from http://wei48221.blogspot.com/2017/11/working-with-ct-sensor.html ) ?

image

This has a DC offest applied so that it can be read by the ADC which cannot tolerate the negaive component. You can remove this bias when taking the analog samples by subtracting 511 (10 bit ADC).