Defining piecewise constant functions in a GUI

I was posting my question on StackOverflow (https://stackoverflow.com/questions/44927697/defining-piecewise-constant-functions-in-a-gui?noredirect=1#comment76852785_44927697) a couple of days ago, but now a commentator referred me to this forum.

Currently, I am working on a program with a GUI. My application computes several things, given a function, which the user can enter. Right now, the users are only able to enter constant functions into my program. I'd like to be able to allow also piecewise-constant functions.

What would be a good interface for a user to enter piecewise functions? The user should be able to enter a finite number of intervals on which the function has a certain constant value. How would this be done nicely?

Thanks in advance

EDIT:

  1. Right now, users can enter constant functions via a simple Textline, where they enter a non-negative real number.
  2. A definition and examples of piecewise constant functions can be found here: https://en.wikipedia.org/wiki/Step_function