Arduino - RobotPlayMelody

Arduino

Reference Language | Libraries | Comparison | Changes

Robot

## playMelody()

#### Description

Plays a melody according to a string of music notes. The input string also contains information about note duration, as well as silences. Must be preceded by `Robot.beginSpeaker()` in `setup()`.

NB : when a melody is playing, all other processes stop

#### Syntax

Robot.playMelody(melody)

#### Parameters

melody: A string of notes to be played and their duration.

The string may contain following chars:
Notes

- c : play "C"
- C : play "#C"
- d : play "D"
- D : play "#D"
- e : play "E"
- f : play "F"
- F : play "#F"
- g : play "G"
- G : play "#G"
- a : play "A"
- A : play "#A"
- b : play "B"
- - : silence

Duration

- 1 : Set the following as full notes
- 2 : Set the following as half notes
- 4 : Set the following as quarter notes
- 8 : Set the following as eigth notes
- . : Set the note duration as its duration plus an half of its duration (Example 1/4 + 1/8)

#### Returns

none

#### Examples

#include <ArduinoRobot.h>
void setup(){
Robot.begin();
Robot.beginSpeaker();//Initialize the sound module
}
void loop(){
char aTinyMelody[] = "8eF-FFga4b.a.g.F.8beee-d2e.1-";// This is what we will play
Robot.playMelody(aTinyMelody);// Play the melody
}
[Get Code]

#### See also

- beginSpeaker()
- beep()
- playFile()

Reference Home

Corrections, suggestions, and new documentation should be posted to the Forum.

The text of the Arduino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.

### Share

### This link has expired.
Please re-subscribe to our Newsletters.

### Subscribe to our Newsletters

Email

Please enter a valid email to subscribe

Arduino Newsletter
Arduino Store Newsletter

### Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy

###### Newsletter

- ©2015 Arduino
- Copyright Notice
- Contact us
- About us
- Careers