Existence of continuous function satisfying a condition After hearing about "locally constant". This question popped up in my mind.

Is there a continuous non-constant function $f: \mathbb{R} \to \mathbb{R}$ which is locally constant everywhere? That is given any $r \in \mathbb{R}$, there exists $\epsilon >0$ such that $f(B_{\epsilon}(r))=\{f(r)\}$. In words, given any $r \in \mathbb{R}$, there is a neighborhood of $r$ where such that the restriction of the function $f$ is constant.

I tried to solve this problem by assuming that $x \neq y$ and then showing that $f(x)=f(y)$, but it is possible that we cannot do that in finite number of steps, and even in countably infinite number of steps. then how can I solve this?
 A: If $f:X\to Y$ is a function that is locally constant at every point and $X$ is connected then $f$ is (globally) constant. So the answer is no with domain $\Bbb R$ in the usual topology. If we give it the discrete metric topology then every function on $\Bbb R$ is locally constant trivially. A complete proof for the connected domain case can be found here.
A: Take $r$ in the image of $f$ and consider $A=\{x\in\mathbb{R}:f(x)\ne r\}$, which is open in $\mathbb{R}$. Let $x\in\mathbb{R}$ such that $f(x)=r$; then there is a neighborhood $U$ of $x$ such that $f(y)=r$, for every $y\in U$. Therefore also $B=\{x\in\mathbb{R}:f(x)=r\}$ is open. Since $\mathbb{R}$ is connected, the only possibility is that $A=\emptyset$, because $B\ne\emptyset$.
So the only case when the function is locally constant is when it is constant.
More generally, if $f\colon X\to Y$ is a locally constant continuous function between topological spaces (metric spaces, if you prefer) is constant in every connected component of the domain.
A: The closest function that comes to mind is the Cantor-Function.
It is continuous, non-constant and its derivative is 0 almost everywhere, in the sense that the derivative doesnt vanish on a lebesgue zero set $A\subset [0,1]$. I hope i didnt miss anything wrong when writing this and could help a little.
