Gene circuits are dynamical systems that regulate cellular behaviors, often using protein signals as inputs and outputs. Here we have developed an optogenetic 'function generator' method for programming tailor-made gene expression signals in live bacterial cells. We designed precomputed light sequences based on experimentally calibrated mathematical models of light-switchable two-component systems and used them to drive intracellular protein levels to match user-defined reference time courses. We used this approach to generate accelerated and linearized dynamics, sinusoidal oscillations with desired amplitudes and periods, and a complex waveform, all with unprecedented accuracy and precision. We also combined the function generator with a dual fluorescent protein reporter system, analogous to a dual-channel oscilloscope, to reveal that a synthetic repressible promoter linearly transforms repressor signals with an approximate 7-min delay. Our approach will enable a new generation of dynamical analyses of synthetic and natural gene circuits, providing an essential step toward the predictive design and rigorous understanding of biological systems.