How to fill a bar constantly between two variables?

I have tried pingpong and sin for this but it goes all the way back to 0 and fills it up to another point but I want it to go back to a variable I want

If I use
fbar.fillamount = Mathf.PingPong(Time.time * 0.5f, 0.2f);

It fills till 0.2f at 0.5f rate and goes back to zero what should I do

PingPong always goes back to 0.

You can use Lerp along with Cos.

Mathf.Lerp(.25f, .75f, (Mathf.Cos(Time.time)+1)*0.5f)

Or use an AnimationCurve.

[SerializeField] AnimationCurve curve;