• @halemmerich, yes, I saw your post for the custom case. That looks pretty good.

    Here is the function to drive the piezo.

    function piezoBuzz(pin, frequency, times, duration, pause) {
      let count = 0;
    
      function buzz() {
        if (count < times) {
          analogWrite(pin, 0.5, {
            freq: frequency
          });
          setTimeout(() => {
            analogWrite(pin, 0);
            setTimeout(() => {
              count++;
              buzz();
            }, pause);
          }, duration);
        }
      }
      buzz();
    }
    

    And here is an example to call the function.

    piezoBuzz(D43, 5600, 2, 200, 200); //UATX pin, 5.6kHz, twice, 200ms pulse, 200ms pause
    
About

Avatar for JeonLab @JeonLab started