Specifically, write a sketch that prints the on/off durations of pushbutton input to the serial port. The output format should be separate lines of the format " ", where value is “1” when the button is pushed and “0” when it is not, and duration is the time duration of that state in milliseconds. You should print the previous state every time the state changes.
For example, if you press the button for one second, then release it for two seconds, then press it for five seconds, then release it again, the output shown on Serial Monitor should be:
You can use the millis() function to get the current time in milliseconds since bootup, which will allow you to calculate the durations.