21 Time Series Output
To have an effect on the real world, we need to be able to produce a physical output that changes as a function of time and other input information. The simplest place to start is producing an analog output that depends only on time. We can read the time since we started from micros(), use sin() to produce a variable result, then use analogWrite() to produce a voltage output on pin A0, which we should be able to see on a multi-meter.
If we connect a wire between pins A0 and A3, we should be able to read that output voltage as an input voltage, using analogRead() faster than the multimeter can follow. (Video 3:53)
For something more complex we need to start thinking procedurally. We can break up the time represented by micros() into smaller periods using the modulo operator, %.
We can use an if/else construct, to do different things at different times within that shorter period. With multiple, nested if/else constructs, we can do many different things to build a test time series waveform with much more interesting characteristics than a simple sine wave. (Video 3:46)
We can package this capability in a function and use it to provide known input when we want to test our measurement code, or use it as output to see how hardware like a servo responds to gradual or rapid changes in its control signals.