Melody Example: Pink Panther Theme

These section contains code snippets for the rust module pink_panther. If you want other songs/bgms notes, you can refer the Rust Embedded Songs repository

Tempo

we declare the tempo for the song(you can also change and observe the result).

#![allow(unused)]
fn main() {
pub const TEMPO: u16 = 120;
}

Melody Array

We define the melody of the Pink Panther theme using the notes and durations in an array. The melody consists of tuple of note frequencies and their corresponding durations. The duration of each note is represented by an integer, where positive values represent normal notes and negative values represent dotted notes.

#![allow(unused)]
fn main() {
pub const MELODY: [(f64, i16); 88] = [
    (REST, 2),
    (REST, 4),
    (REST, 8),
    (NOTE_DS4, 8),
    (NOTE_E4, -4),
    (REST, 8),
    (NOTE_FS4, 8),
    (NOTE_G4, -4),
    (REST, 8),
    (NOTE_DS4, 8),
    (NOTE_E4, -8),
    (NOTE_FS4, 8),
    (NOTE_G4, -8),
    (NOTE_C5, 8),
    (NOTE_B4, -8),
    (NOTE_E4, 8),
    (NOTE_G4, -8),
    (NOTE_B4, 8),
    (NOTE_AS4, 2),
    (NOTE_A4, -16),
    (NOTE_G4, -16),
    (NOTE_E4, -16),
    (NOTE_D4, -16),
    (NOTE_E4, 2),
    (REST, 4),
    (REST, 8),
    (NOTE_DS4, 4),
    (NOTE_E4, -4),
    (REST, 8),
    (NOTE_FS4, 8),
    (NOTE_G4, -4),
    (REST, 8),
    (NOTE_DS4, 8),
    (NOTE_E4, -8),
    (NOTE_FS4, 8),
    (NOTE_G4, -8),
    (NOTE_C5, 8),
    (NOTE_B4, -8),
    (NOTE_G4, 8),
    (NOTE_B4, -8),
    (NOTE_E5, 8),
    (NOTE_DS5, 1),
    (NOTE_D5, 2),
    (REST, 4),
    (REST, 8),
    (NOTE_DS4, 8),
    (NOTE_E4, -4),
    (REST, 8),
    (NOTE_FS4, 8),
    (NOTE_G4, -4),
    (REST, 8),
    (NOTE_DS4, 8),
    (NOTE_E4, -8),
    (NOTE_FS4, 8),
    (NOTE_G4, -8),
    (NOTE_C5, 8),
    (NOTE_B4, -8),
    (NOTE_E4, 8),
    (NOTE_G4, -8),
    (NOTE_B4, 8),
    (NOTE_AS4, 2),
    (NOTE_A4, -16),
    (NOTE_G4, -16),
    (NOTE_E4, -16),
    (NOTE_D4, -16),
    (NOTE_E4, -4),
    (REST, 4),
    (REST, 4),
    (NOTE_E5, -8),
    (NOTE_D5, 8),
    (NOTE_B4, -8),
    (NOTE_A4, 8),
    (NOTE_G4, -8),
    (NOTE_E4, -8),
    (NOTE_AS4, 16),
    (NOTE_A4, -8),
    (NOTE_AS4, 16),
    (NOTE_A4, -8),
    (NOTE_AS4, 16),
    (NOTE_A4, -8),
    (NOTE_AS4, 16),
    (NOTE_A4, -8),
    (NOTE_G4, -16),
    (NOTE_E4, -16),
    (NOTE_D4, -16),
    (NOTE_E4, 16),
    (NOTE_E4, 16),
    (NOTE_E4, 2),
];
}