pdf-icon

Arduino Guide

Buzzer

StamPLC Buzzer buzzer related APIs and example program.

Example Program

/*
 *SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
 *
 *SPDX-License-Identifier: MIT
 */
#include <Arduino.h>
#include <M5StamPLC.h>

void setup()
{
    /* Init M5StamPLC */
    M5StamPLC.begin();

    /* Play tone */
    // M5StamPLC.tone(frequency, duration);

    /* Stop playing tone */
    // M5StamPLC.noTone();
}

void loop()
{
    M5StamPLC.tone(523, 50);
    delay(1000);
    M5StamPLC.tone(659, 50);
    delay(1000);
    M5StamPLC.tone(880, 50);
    delay(1000);
}

tone

Function Prototype:

void tone(unsigned int frequency, unsigned long duration = 0UL);

Function Description:

  • Drives the buzzer to play at the specified frequency and sets the duration of the tone.

Parameters:

  • unsigned int frequency:
    • Driving frequency (Hz)
  • unsigned long duration:
    • Playback duration (ms)

Return Value:

  • null

noTone

Function Prototype:

void noTone();

Function Description:

  • Stops the buzzer from playing

Parameters:

  • null

Return Value:

  • null
On This Page