PlayTune

Purpose

Play a tune on the CrcDuino buzzer.

When to use

When you want to play a sound (for debugging).

Where to use

Inside the loop function.

Calling this function cancels the previous sound. Make sure to not call it repeatedly.

Returns

N/A

Main prototype and parameters

void CrcLib::PlayTune(const Note notes[], bool repeat)

The following parameters must be passed to the function for it to work properly:

  • A sequence of notes to play

  • Whether to loop the sound

Overloads

void CrcLib::PlayTune(Tune* tune)

A more advanced version of the function you probably don’t need. If you want to use it, read CrcBuzz.h for more info.

Examples

#include <CrcLib.h> // See the page about Note // Define a song using { <duration in ms>, <note frequency in Hz> } Note notes[] = { { 250, NOTE_B4 }, { 500, NOTE_F5 }, Note::END }; CrcLib::Timer timer; void setup() { CrcLib::Initialize(); timer.Start(2000); } void loop() { CrcLib::Update(); if (timer.IsFinished()) { // start the tune each 2s timer.Next(); CrcLib::PlayTune(notes, false); } }

Related articles