Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: Help with Sawtooth LFO Indicator

  1. #1

    Help with Sawtooth LFO Indicator

    Hi everyone,

    I'm trying to figure out something really simple--how to light an LED indicator proportionally to a Sawtooth LFO. So at the beginning of the wave, the LED would be completely dimmed, and by the end of the wave, the LED would be full brightness.

    I'm using AudioAnalyzePeak right now, which is great, but it measures the waveforms negative amplitude the same as the positive amplitude, like so:
    Click image for larger version. 

Name:	Screen Shot 2021-06-03 at 10.36.11 AM.jpg 
Views:	8 
Size:	43.9 KB 
ID:	24968

    This makes the LED illuminate more like a triangle wave than like a Sawtooth.

    Any ideas how I could modify this code to make the positive waveform peaks align with maximum LED brightness, and negative waveform peaks align with a fully dimmed LED?

    Here's a simple sketch where I'm printing the waveform value to Serial. That value would be used for the LED brightness.

    Thank you so much for any ideas.

    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    // GUItool: begin automatically generated code
    AudioSynthWaveform       LFO;   //xy=1280.5831108093262,929.1666927337646
    AudioAnalyzePeak         peakMeter;          //xy=1445.333152770996,927.9166450500488
    AudioConnection          patchCord1(LFO, peakMeter);
    AudioOutputI2S           i2s2;           //xy=1883.333333333333,811.6666666666665
    AudioControlSGTL5000     sgtl5000_1;     //xy=1989.9999999999998,961.6666666666665
    // GUItool: end automatically generated code
    void setup() {
      LFO.begin(1, .5, WAVEFORM_SAWTOOTH);
    void loop() {
      if (peakMeter.available()) {
        double peakValue =;  

  2. #2
    Use the DC offset function.

  3. #3
    Genius. That's all it took. Thanks @kallikak.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts