I don't think there can be for $2$. To see this, suppose there is sucha function $f$ and consider two points $x_1,x_2$ where it takes some given value $y$. Between these points $f(x)$ is either always greater than $y$ or always less. Without loss of generality assume the former. Now there is some maximum value $z$ taken between these points, which is attained because $f$ is continuous. $z$ can only be taken at one point inside the range (since otherwise the function is constant on an interval, contradiction), but also every the function must be less than $y$ outside the interval since otherwise some value slightly more than $y$ would be taken three times. This means $z$ is only taken once, contradiction.
There is such a function for $3$. One example is the function defined by the following properties:
- $f(0)=0$, $f(1)=1$, $f(2)=0$, $f(3)=1$, $f(4)=2$, $f(5)=1$, $f(6)=2$, $f(7)=3$, $f(8)=2$ and so on (after the first step it just repeats down, up, up)
- $f$ is linear between integer values
- $f$ is an odd function.