RC Time Constant simulator
Your first formula presents charging from zero to Vs. The 2nd formula presents discharging from Vs to zero. With superposition you get for charging from A to B, no matter which is higher:

Vc = Aexp(-t/RC) + B(1-exp(-t/RC)

A is the initial voltage in the capacitor, B is the DC applied through R.

But these are still 2 levels only. If you want to apply an arbitary input voltage instead of a DC level, you must rely on the general law how capacitors work.

The general law is that the voltage changing rate in the capacitor is =Charging current/Capacitance. If the charging current (negative for discharging) is as amperes, the capacitance is as Farads, the rate is as Volts/second.

The charging current is the difference of the input voltage and already charged voltage divided by R, said Mr. Ohm and Mr. Kirchoff in the first half of 1800's. The formula is as OK for discharging.

Your job is to cumulate (=integrate) the voltage by starting from the initial voltage. You calculate the voltage increments in small timesteps and add them to your initial voltage. The increment is the changing rate multiplied by the timestep. The method is known as Euler's numerical integration.

Use timestep about RC/50 for a start. Reduce the timestep and recalculate from the start until you get the same result accurately enough for your purposes.

A sidenote: Trapezoidal integration allows longer timesteps without reducing the accuracy, but Euler's method is the simplest one.