pdf-icon

Arduino Quick Start

StamPLC Buzzer

StamPLC Buzzer buzzer related APIs and example program.

Example Program

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/*
*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