function setup() {
  createCanvas(800,400);
  noFill();

  freqLabel = createP('Frequency: ');
  freqSlider = createSlider(1, 700, freq);

  ampLabel = createP('Amplitude: ' + amp);
  ampSlider = createSlider(0.0, 100.0, amp*100);

  button = createButton('start');
  button.mousePressed(toggleOsc);

  // Other types of oscillators include TriOsc, SawOsc, SqrOsc, and generic Oscillator.
  osc = new p5.SinOsc(freq);
  osc.amp(amp);

  p = createP('Current Waveform: ' + osc.getType());

  // these buttons will change the osc's waveform
  sine = createButton('sine');
  sine.mousePressed(setSine);
  saw = createButton('sawtooth');
  saw.mousePressed(setSawtooth);
  tri = createButton('triangle');
  tri.mousePressed(setTriangle);
  sq = createButton('square');
  sq.mousePressed(setSquare);

  // create an fft to analyze the audio
  fft = new p5.FFT();
}
Example: change the frequency of an oscillator and visualize the waveform