This looks like a job for 1d interpolation, which isn’t currently easy to do. Check this out though: Forced ODEs, a start for a case study?.
There might be problems with the ODE solver changing constants discontinuously like that, so you should probably use the interpolation stuff in that forced ODEs thread.