Giter VIP home page Giter VIP logo

arduino-songs's Introduction

Songs for playing on Arduino boards.

Usage

Every code here should run on every arduino board without problems. The sketches rely solely on the tone() function from Arduino, so the sounds are all monophonic. On the bright side, libraries are not required.

If you want to compare the code with the original score, I try to group the notes in a measure as one line of ccode and the staves as groups of lines. However, in some cases notes will be tied together among measures or be dotted and this rule is broken.

Hardware

Just connect an piezo to the board and you are good to go. Pin 11 is used in every sketch because some piezo speakers can be connected between it and the close GND pin without any wiring. You can use basically any pin, as long as they can be used as digital pins (pins A6 and A7 of the Arduino Nano and mini are analog only). Just remember to assign the pin number to the buzzer variable.

alt tag

There are two kinds of piezo buzzers: active and passive. The active one that plays a specific pitch when powevered and is not good for this purpose. The passive kind functions like a speaker, reproducing the pitch you apply to it. You can test the piezo speaker with the "blink" example, the good piezo speaker will just click, while the other kind will play a pitch every other second.

List of tunes

Movies

Games

Classic

Others

Copyright

Every sketch here has been written by myself, although based on scores I found online or books I own. These scores are linked in each file when possible. You can use the sketches for anything, I only kindly ask that you give credit if you use these codes on a tutorial, video, example, etc.

arduino-songs's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

arduino-songs's Issues

Ability to play mutliple songs

Hello! I love this repository and I'm looking to try and abstract a bit of it and play multiple songs from the same sketch. However, the following sketch doesnt do anything. My goal is to have various Melodies defiined above and then pass them to the play function.

#define NOTE_B0  31
#define NOTE_C1  33
#define NOTE_CS1 35
#define NOTE_D1  37
#define NOTE_DS1 39
#define NOTE_E1  41
#define NOTE_F1  44
#define NOTE_FS1 46
#define NOTE_G1  49
#define NOTE_GS1 52
#define NOTE_A1  55
#define NOTE_AS1 58
#define NOTE_B1  62
#define NOTE_C2  65
#define NOTE_CS2 69
#define NOTE_D2  73
#define NOTE_DS2 78
#define NOTE_E2  82
#define NOTE_F2  87
#define NOTE_FS2 93
#define NOTE_G2  98
#define NOTE_GS2 104
#define NOTE_A2  110
#define NOTE_AS2 117
#define NOTE_B2  123
#define NOTE_C3  131
#define NOTE_CS3 139
#define NOTE_D3  147
#define NOTE_DS3 156
#define NOTE_E3  165
#define NOTE_F3  175
#define NOTE_FS3 185
#define NOTE_G3  196
#define NOTE_GS3 208
#define NOTE_A3  220
#define NOTE_AS3 233
#define NOTE_B3  247
#define NOTE_C4  262
#define NOTE_CS4 277
#define NOTE_D4  294
#define NOTE_DS4 311
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_FS4 370
#define NOTE_G4  392
#define NOTE_GS4 415
#define NOTE_A4  440
#define NOTE_AS4 466
#define NOTE_B4  494
#define NOTE_C5  523
#define NOTE_CS5 554
#define NOTE_D5  587
#define NOTE_DS5 622
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_FS5 740
#define NOTE_G5  784
#define NOTE_GS5 831
#define NOTE_A5  880
#define NOTE_AS5 932
#define NOTE_B5  988
#define NOTE_C6  1047
#define NOTE_CS6 1109
#define NOTE_D6  1175
#define NOTE_DS6 1245
#define NOTE_E6  1319
#define NOTE_F6  1397
#define NOTE_FS6 1480
#define NOTE_G6  1568
#define NOTE_GS6 1661
#define NOTE_A6  1760
#define NOTE_AS6 1865
#define NOTE_B6  1976
#define NOTE_C7  2093
#define NOTE_CS7 2217
#define NOTE_D7  2349
#define NOTE_DS7 2489
#define NOTE_E7  2637
#define NOTE_F7  2794
#define NOTE_FS7 2960
#define NOTE_G7  3136
#define NOTE_GS7 3322
#define NOTE_A7  3520
#define NOTE_AS7 3729
#define NOTE_B7  3951
#define NOTE_C8  4186
#define NOTE_CS8 4435
#define NOTE_D8  4699
#define NOTE_DS8 4978
#define REST      0



// change this to whichever pin you want to use
int buzzer = D1;

// notes of the moledy followed by the duration.
// a 4 means a quarter note, 8 an eighteenth , 16 sixteenth, so on
// !!negative numbers are used to represent dotted notes,
// so -4 means a dotted quarter note, that is, a quarter plus an eighteenth!!
int cantinaMelody[] = {
  
  // Cantina BAnd - Star wars 
  // Score available at https://musescore.com/user/6795541/scores/1606876
  NOTE_B4,-4, NOTE_E5,-4, NOTE_B4,-4, NOTE_E5,-4, 
  NOTE_B4,8,  NOTE_E5,-4, NOTE_B4,8, REST,8,  NOTE_AS4,8, NOTE_B4,8, 
  NOTE_B4,8,  NOTE_AS4,8, NOTE_B4,8, NOTE_A4,8, REST,8, NOTE_GS4,8, NOTE_A4,8, NOTE_G4,8,
  NOTE_G4,4,  NOTE_E4,-2, 
  NOTE_B4,-4, NOTE_E5,-4, NOTE_B4,-4, NOTE_E5,-4, 
  NOTE_B4,8,  NOTE_E5,-4, NOTE_B4,8, REST,8,  NOTE_AS4,8, NOTE_B4,8,

  NOTE_A4,-4, NOTE_A4,-4, NOTE_GS4,8, NOTE_A4,-4,
  NOTE_D5,8,  NOTE_C5,-4, NOTE_B4,-4, NOTE_A4,-4,
  NOTE_B4,-4, NOTE_E5,-4, NOTE_B4,-4, NOTE_E5,-4, 
  NOTE_B4,8,  NOTE_E5,-4, NOTE_B4,8, REST,8,  NOTE_AS4,8, NOTE_B4,8,
  NOTE_D5,4, NOTE_D5,-4, NOTE_B4,8, NOTE_A4,-4,
  NOTE_G4,-4, NOTE_E4,-2,
  NOTE_E4, 2, NOTE_G4,2,
  NOTE_B4, 2, NOTE_D5,2,

  NOTE_F5, -4, NOTE_E5,-4, NOTE_AS4,8, NOTE_AS4,8, NOTE_B4,4, NOTE_G4,4, 
  
  
  

};



void playMelody(int melody[]){



    // change this to make the song slower or faster
    int tempo = 140;
    
      // sizeof gives the number of bytes, each int value is composed of two bytes (16 bits)
    // there are two values per note (pitch and duration), so for each note there are four bytes
    int notes = sizeof(melody) / sizeof(melody[0]) / 2;
    // this calculates the duration of a whole note in ms
    int wholenote = (60000 * 2) / tempo;
    
    int divider = 0, noteDuration = 0;

   for (int thisNote = 0; thisNote < notes * 2; thisNote = thisNote + 2) {

    // calculates the duration of each note
    divider = melody[thisNote + 1];
    if (divider > 0) {
      // regular note, just proceed
      noteDuration = (wholenote) / divider;
    } else if (divider < 0) {
      // dotted notes are represented with negative durations!!
      noteDuration = (wholenote) / abs(divider);
      noteDuration *= 1.5; // increases the duration in half for dotted notes
    }

    // we only play the note for 90% of the duration, leaving 10% as a pause
    tone(buzzer, melody[thisNote], noteDuration*0.9);

    // Wait for the specief duration before playing the next note.
    delay(noteDuration);
    
    // stop the waveform generation before the next note.
    noTone(buzzer);
  }
}

void setup() {
    Serial.begin(115200);
Serial.println("Play stuff");

  // iterate over the notes of the melody. 
  // Remember, the array is twice the number of notes (notes + durations)
 playMelody(cantinaMelody);

}

void loop() {
  // no need to repeat the melody.
}

If I change the following to use catinaMelody from global rather than the melody I pass it from the function, but that defeats the purpose. Am I missing something basic?

    // change this to make the song slower or faster
    int tempo = 140;
    
      // sizeof gives the number of bytes, each int value is composed of two bytes (16 bits)
    // there are two values per note (pitch and duration), so for each note there are four bytes
    int notes = sizeof(melody) / sizeof(melody[0]) / 2;
    // this calculates the duration of a whole note in ms
    int wholenote = (60000 * 2) / tempo;

How can I contribute to this repo?

I used you code as an example to translate scores into sketch.
So far I've got only Ride of the Valkyries, but I plan to translate few more for my project soon.
It would be nice if I could add those melodies to this repo for others to use, but I don't have access.

Attached is a code for your reference, feel free to use it.
rideofthevalkyries.txt

Just a thank you!

Thank you mate. I like your songs! I'm using "Pulo da Gaita" for my small project. Thanks again!

Tetris is wrong

lines 117 and 127 should be "NOTE_C5, 4, NOTE_A4,4, NOTE_A4,4, NOTE_B4,8, NOTE_C5,8,"

you added an extra eighth note in the sequence

This nice music on ESP32

Great work at first.

Looked for music I can use on my ESP32 with the Tone32.h library. This here works well till the first note with a "-".
Then I removed it and now the code works.

I made from

"NOTE_D5, -4,"
"NOTE_D5, 4,"

Now he play the song.

Esp32?

Hello, can those songs be used on esp32 somehow? Tone/ noTone doesn't seem to work, maybe I messed something up with libraries.

Songs are unlicensed

I was hoping to use this song data in an open source project also hosted here on Github, with lots of attribution etc. However at present the code is not licensed with an open source license (or indeed with any license). The author helpfully states "You can use the sketches for anything, I only kindly ask that you give credit if you use these codes on a tutorial, video, example, etc.", but this isn't sufficient to include code in an open source licensed project.

May I suggest that the author perhaps license the code as MIT or (better yet) Apache 2.0? It'd help a lot.

The Godfather theme not according to sheet. Wrong note.

The first section is currently:
REST, 4, REST, 8, REST, 8, REST, 8, NOTE_E4, 8, NOTE_A4, 8, NOTE_C5, 8, //1 NOTE_B4, 8, NOTE_A4, 8, NOTE_C5, 8, NOTE_A4, 8, NOTE_B4, 8, NOTE_A4, 8, NOTE_F4, 8, NOTE_G4, 8, NOTE_E4, 2, NOTE_E4, 8, NOTE_A4, 8, NOTE_C5, 8, NOTE_B4, 8, NOTE_A4, 8, NOTE_C5, 8, NOTE_A4, 8, NOTE_C5, 8, NOTE_A4, 8, NOTE_E4, 8, NOTE_DS4, 8,

And it should be:
REST, 4, REST, 8, REST, 8, REST, 8, NOTE_E4, 8, NOTE_A4, 8, NOTE_C5, 8, //1 NOTE_B4, 8, NOTE_A4, 8, NOTE_C5, 8, NOTE_A4, 8, NOTE_B4, 8, NOTE_A4, 8, NOTE_F4, 8, NOTE_G4, 8, NOTE_E4, 2, NOTE_E4, 8, NOTE_A4, 8, NOTE_C5, 8, NOTE_B4, 8, NOTE_A4, 8, NOTE_C5, 8, NOTE_A4, 8, NOTE_B4, 8, NOTE_A4, 8, NOTE_E4, 8, NOTE_DS4, 8,

It sounded off and I just checked with the music sheet and the original song.

Buttons don't work while buzzer is playing

Hi!

Firstly, I loved the songs. And thank you for your work!

Secondly, I'm building a little game with an arduino mega 2560. It's really simple. 2 People will battle to see who has the faster finger press (Basically they'll define the number of button press and see who presses faster).

Basically, I have 5 buttons (2 arcade and 3 simple push buttons), 1 LCD i2C 16,2 screen, 1 4Digit 7 segment display and a buzzer.

On my code (I haven't finished it yet) I was trying to test the functionalities (pressing any of the buttons while the buzzer is playing) I implemented so far, and the buttons stopped working while the music was playing.

If I comment the function that makes the music play and re-upload to my arduino, all of the buttons work again.

I don't know why this is happening. I was hopping to play 3 musics. 1. while the player are setting up the game (defining the number of presses etc), 2. while the game is running (while the are pressing the buttons) and 3. when someone wins.

If anyone could help me, I would be really grateful.

Anyway, thank you!

EDIT: I tried putting the Music() function on the setup(), and the buttons still didn't work while the song was playing. After it ended the buttons work normally. Don't know why. (Welcome to programming I guess?)

(I'll post the code here!)
(I've divided the code into 2 tabs. The main one has almost everything. The second one just has the Music() function).
(FYI, I'm brazilian. So some parts of the code has a comment or two in portuguese. :/ ).

//////////////////
//CODE ONE//
//////////////////

// Libraries
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// Define cada nota para um frequencia em hertz
#define NOTE_B0  31
#define NOTE_C1  33
#define NOTE_CS1 35
#define NOTE_D1  37
#define NOTE_DS1 39
#define NOTE_E1  41
#define NOTE_F1  44
#define NOTE_FS1 46
#define NOTE_G1  49
#define NOTE_GS1 52
#define NOTE_A1  55
#define NOTE_AS1 58
#define NOTE_B1  62
#define NOTE_C2  65
#define NOTE_CS2 69
#define NOTE_D2  73
#define NOTE_DS2 78
#define NOTE_E2  82
#define NOTE_F2  87
#define NOTE_FS2 93
#define NOTE_G2  98
#define NOTE_GS2 104
#define NOTE_A2  110
#define NOTE_AS2 117
#define NOTE_B2  123
#define NOTE_C3  131
#define NOTE_CS3 139
#define NOTE_D3  147
#define NOTE_DS3 156
#define NOTE_E3  165
#define NOTE_F3  175
#define NOTE_FS3 185
#define NOTE_G3  196
#define NOTE_GS3 208
#define NOTE_A3  220
#define NOTE_AS3 233
#define NOTE_B3  247
#define NOTE_C4  262
#define NOTE_CS4 277
#define NOTE_D4  294
#define NOTE_DS4 311
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_FS4 370
#define NOTE_G4  392
#define NOTE_GS4 415
#define NOTE_A4  440
#define NOTE_AS4 466
#define NOTE_B4  494
#define NOTE_C5  523
#define NOTE_CS5 554
#define NOTE_D5  587
#define NOTE_DS5 622
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_FS5 740
#define NOTE_G5  784
#define NOTE_GS5 831
#define NOTE_A5  880
#define NOTE_AS5 932
#define NOTE_B5  988
#define NOTE_C6  1047
#define NOTE_CS6 1109
#define NOTE_D6  1175
#define NOTE_DS6 1245
#define NOTE_E6  1319
#define NOTE_F6  1397
#define NOTE_FS6 1480
#define NOTE_G6  1568
#define NOTE_GS6 1661
#define NOTE_A6  1760
#define NOTE_AS6 1865
#define NOTE_B6  1976
#define NOTE_C7  2093
#define NOTE_CS7 2217
#define NOTE_D7  2349
#define NOTE_DS7 2489
#define NOTE_E7  2637
#define NOTE_F7  2794
#define NOTE_FS7 2960
#define NOTE_G7  3136
#define NOTE_GS7 3322
#define NOTE_A7  3520
#define NOTE_AS7 3729
#define NOTE_B7  3951
#define NOTE_C8  4186
#define NOTE_CS8 4435
#define NOTE_D8  4699
#define NOTE_DS8 4978
#define REST      0

// change this to make the song slower or faster
int tempo = 108; // 108 is standard.

// change this to whichever pin you want to use
int buzzer = 27;

// notes of the moledy followed by the duration.
// a 4 means a quarter note, 8 an eighteenth , 16 sixteenth, so on
// !!negative numbers are used to represent dotted notes,
// so -4 means a dotted quarter note, that is, a quarter plus an eighteenth!!
int melody[] = {
  
  NOTE_E4,2, NOTE_G4,4,
  NOTE_D4,2, NOTE_C4,8, NOTE_D4,8, 
  NOTE_E4,2, NOTE_G4,4,
  NOTE_D4,-2,
  NOTE_E4,2, NOTE_G4,4,
  NOTE_D5,2, NOTE_C5,4,
  NOTE_G4,2, NOTE_F4,8, NOTE_E4,8, 
  NOTE_D4,-2,
  NOTE_E4,2, NOTE_G4,4,
  NOTE_D4,2, NOTE_C4,8, NOTE_D4,8, 
  NOTE_E4,2, NOTE_G4,4,
  NOTE_D4,-2,
  NOTE_E4,2, NOTE_G4,4,

  NOTE_D5,2, NOTE_C5,4,
  NOTE_G4,2, NOTE_F4,8, NOTE_E4,8, 
  NOTE_F4,8, NOTE_E4,8, NOTE_C4,2,
  NOTE_F4,2, NOTE_E4,8, NOTE_D4,8, 
  NOTE_E4,8, NOTE_D4,8, NOTE_A3,2,
  NOTE_G4,2, NOTE_F4,8, NOTE_E4,8, 
  NOTE_F4,8, NOTE_E4,8, NOTE_C4,4, NOTE_F4,4,
  NOTE_C5,-2, 
  
};

// sizeof gives the number of bytes, each int value is composed of two bytes (16 bits)
// there are two values per note (pitch and duration), so for each note there are four bytes
int notes = sizeof(melody) / sizeof(melody[0]) / 2;

// this calculates the duration of a whole note in ms
int wholenote = (60000 * 4) / tempo;

int divider = 0, noteDuration = 0;

// Seta o adress da LCD para 0x3F para 16 chars e 2 linhas do display
LiquidCrystal_I2C lcd(0x3F, 16, 2);

// Definindo as variaveis
  // Botoes
int numberButtons = 5;   // Numero total de botoes
int startPin = 22;       // Onde comeca a porta dos botoes
int buttons[5];          // Lista com todos os botoes
boolean buttonsBool[5];  // Bool pra checar o estado do botao

  // Buzzer
const int miniSom = 27;  // Pin do MiniSom
  // Jogo
int pressNumber = 0;  // Numero total de vezes que vao ser apertadas no jogo

void setup() {
  Serial.begin(9600);
  // Inicilizando todos os botoes em seus respectivos pins
  for (int i = 0; i < numberButtons; i++)
    buttons[i] = i + startPin;
  // Setando todos os botoes para o estado de falso
  for (int i = 0; i < numberButtons; i++)
    buttonsBool[i] = false;
  // Setando todos os botoes para o estado de input pullup
  for (int i = 0; i < numberButtons; i++)
    pinMode(buttons[i], INPUT_PULLUP);

  pinMode(miniSom, OUTPUT);

  // inicializando o lcd
  lcd.init();
  // Liga a luz de fundo e limpa a tela com o clear
  lcd.backlight();
  lcd.clear();
}

void loop() {
  //Music();
  ButtonPressing();
  /*
  digitalWrite(miniSom, HIGH);
  delay(1000);
  digitalWrite(miniSom, LOW);
  delay(1000);
  */
}

void ButtonPressing() {
  // while (digitalRead(buttons[2] == HIGH))
  // {
  for (int i = 0; i < numberButtons; i++) {
    if (!buttonsBool[i]) {
      if (digitalRead(buttons[i]) == LOW) {
        if (i == 0) {
          pressNumber++;
          lcd.clear();
          lcd.print(pressNumber);
          buttonsBool[i] = true;
        } else if (i == 1) {
          pressNumber += 10;
          lcd.clear();
          lcd.print(pressNumber);
          buttonsBool[i] = true;
        } else if (i == 2) {
          lcd.clear();
          pressNumber = 0;
        } else if (i == 3) {
          lcd.clear();
          lcd.print("Player 1 funcionando!");
          buttonsBool[i] = true;
        } else if (i == 4) {
          lcd.clear();
          lcd.print("Player 2 funcionando!");
          buttonsBool[i] = true;
        }
      }
    } else {
      if (digitalRead(buttons[i]) == HIGH) {
        buttonsBool[i] = false;
      }
    }
  }
  delay(15);
}

//////////////////
//CODE TWO//
//////////////////

void Music(){
    // iterate over the notes of the melody. 
  // Remember, the array is twice the number of notes (notes + durations)
  for (int thisNote = 0; thisNote < notes * 2; thisNote = thisNote + 2) {

    // calculates the duration of each note
    divider = melody[thisNote + 1];
    if (divider > 0) {
      // regular note, just proceed
      noteDuration = (wholenote) / divider;
    } else if (divider < 0) {
      // dotted notes are represented with negative durations!!
      noteDuration = (wholenote) / abs(divider);
      noteDuration *= 1.5; // increases the duration in half for dotted notes
    }

    // we only play the note for 90% of the duration, leaving 10% as a pause
    tone(buzzer, melody[thisNote], noteDuration*0.9);

    // Wait for the specief duration before playing the next note.
    delay(noteDuration);
    
    // stop the waveform generation before the next note.
    noTone(buzzer);
  }
}

Pac Man theme

Hi, I love your repo, it trully rocks ! Do you intend to implement PacMan theme ?

I'll use your work in a fun DIY project, I'l quote you.

Have a nice day.
Kind Regards,
Adrien

Non-Blocking Code

Amazing work! Kudos!

I made some changes to your code to make it non-blocking: instead of delay statements for each note and program logic waiting for the song to end, my changes allow for program execution while the tunes are being played.

Also I added a flag that can stop tune playback before it ends (for example if program logic requires it).

I also added the option to have up to 10 tunes selectable either by user input or by program logic.

Thanks!

Note: I don't know how to upload programs into a reported issue other than presenting the full code using markup language, so I renamed the NonBlockingTunes.INO and the tunes.h files to .TXT so that they could be copied here.

NonBlockingTunes.txt
tunes.txt

Add Megalovania(Undertale theme) *Look in comment for code*

CODE

// Megalovania, Toby Fox
// Notes at https://pianoletternotes.blogspot.com/2017/10/megalovania-undertale-theme.html

#define NOTE_B0  31
#define NOTE_C1  33
#define NOTE_CS1 35
#define NOTE_D1  37
#define NOTE_DS1 39
#define NOTE_E1  41
#define NOTE_F1  44
#define NOTE_FS1 46
#define NOTE_G1  49
#define NOTE_GS1 52
#define NOTE_A1  55
#define NOTE_AS1 58
#define NOTE_B1  62
#define NOTE_C2  65
#define NOTE_CS2 69
#define NOTE_D2  73
#define NOTE_DS2 78
#define NOTE_E2  82
#define NOTE_F2  87
#define NOTE_FS2 93
#define NOTE_G2  98
#define NOTE_GS2 104
#define NOTE_A2  110
#define NOTE_AS2 117
#define NOTE_B2  123
#define NOTE_C3  131
#define NOTE_CS3 139
#define NOTE_D3  147
#define NOTE_DS3 156
#define NOTE_E3  165
#define NOTE_F3  175
#define NOTE_FS3 185
#define NOTE_G3  196
#define NOTE_GS3 208
#define NOTE_A3  220
#define NOTE_AS3 233
#define NOTE_B3  247
#define NOTE_C4  262
#define NOTE_CS4 277
#define NOTE_D4  294
#define NOTE_DS4 311
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_FS4 370
#define NOTE_G4  392
#define NOTE_GS4 415
#define NOTE_A4  440
#define NOTE_AS4 466
#define NOTE_B4  494
#define NOTE_C5  523
#define NOTE_CS5 554
#define NOTE_D5  587
#define NOTE_DS5 622
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_FS5 740
#define NOTE_G5  784
#define NOTE_GS5 831
#define NOTE_A5  880
#define NOTE_AS5 932
#define NOTE_B5  988
#define NOTE_C6  1047
#define NOTE_CS6 1109
#define NOTE_D6  1175
#define NOTE_DS6 1245
#define NOTE_E6  1319
#define NOTE_F6  1397
#define NOTE_FS6 1480
#define NOTE_G6  1568
#define NOTE_GS6 1661
#define NOTE_A6  1760
#define NOTE_AS6 1865
#define NOTE_B6  1976
#define NOTE_C7  2093
#define NOTE_CS7 2217
#define NOTE_D7  2349
#define NOTE_DS7 2489
#define NOTE_E7  2637
#define NOTE_F7  2794
#define NOTE_FS7 2960
#define NOTE_G7  3136
#define NOTE_GS7 3322
#define NOTE_A7  3520
#define NOTE_AS7 3729
#define NOTE_B7  3951
#define NOTE_C8  4186
#define NOTE_CS8 4435
#define NOTE_D8  4699
#define NOTE_DS8 4978
#define REST 0

// change this to make the song slower or faster
int tempo=150; 

// change this to whichever pin you want to use
int buzzer = 11;

// notes of the melody followed by the duration.
// a 4 means a quarter note, 8 an eighteenth , 16 sixteenth, so on
// !!negative numbers are used to represent dotted notes,
// so -4 means a dotted quarter note, that is, a quarter plus an eighteenth!!
int melody[] = {
  
  NOTE_D4, 12,  NOTE_D4, 12,  NOTE_D5, 12,  REST, 16,  NOTE_A4, 8,
  REST, 12,
  NOTE_GS4, 8,  REST, 16,  NOTE_G4, 12,  REST, 16,  NOTE_F4, 8,  REST, 20,  NOTE_D4, 16,  NOTE_F4, 16,  NOTE_G4, 12,

  NOTE_C4, 12,  NOTE_C4, 12,  NOTE_D5, 12,  REST, 16,  NOTE_A4, 8,
  REST, 12, 
  NOTE_GS4, 8,  REST, 16,  NOTE_G4, 12,  REST, 16,  NOTE_F4, 8,  REST, 20,  NOTE_D4, 16,  NOTE_F4, 16,  NOTE_G4, 12,

  NOTE_B3, 12,  NOTE_B3, 12,  NOTE_D5, 12,  REST, 16,  NOTE_A4, 8,
  REST, 12,
  NOTE_GS4, 8,  REST, 16,  NOTE_G4, 12,  REST, 16,  NOTE_F4, 8,  REST, 20,  NOTE_D4, 16,  NOTE_F4, 16,  NOTE_G4, 12,

  NOTE_AS3, 8,  NOTE_AS3, 8,  NOTE_D5, 12,  NOTE_A4, 8,
  REST, 12,
  NOTE_GS4, 8,  REST, 16,  NOTE_G4, 12,  REST, 16,  NOTE_F4, 8,  REST, 20,  NOTE_D4, 16,  NOTE_F4, 16,  NOTE_G4, 12,


  NOTE_D4, 12,  NOTE_D4, 12,  NOTE_D5, 12,  REST, 16,  NOTE_A4, 8,
  REST, 12,
  NOTE_GS4, 8,  REST, 16,  NOTE_G4, 12,  REST, 16,  NOTE_F4, 8,  REST, 20,  NOTE_D4, 16,  NOTE_F4, 16,  NOTE_G4, 12,

  NOTE_C4, 12,  NOTE_C4, 12,  NOTE_D5, 12,  REST, 16,  NOTE_A4, 8,
  REST, 12, 
  NOTE_GS4, 8,  REST, 16,  NOTE_G4, 12,  REST, 16,  NOTE_F4, 8,  REST, 20,  NOTE_D4, 16,  NOTE_F4, 16,  NOTE_G4, 12,

  NOTE_B3, 12,  NOTE_B3, 12,  NOTE_D5, 12,  REST, 16,  NOTE_A4, 8,
  REST, 12,
  NOTE_GS4, 8,  REST, 16,  NOTE_G4, 12,  REST, 16,  NOTE_F4, 8,  REST, 20,  NOTE_D4, 16,  NOTE_F4, 16,  NOTE_G4, 12,

  NOTE_AS3, 8,  NOTE_AS3, 8,  NOTE_D5, 12,  NOTE_A4, 8,
  REST, 12,
  NOTE_GS4, 8,  REST, 16,  NOTE_G4, 12,  REST, 16,  NOTE_F4, 8,  REST, 20,  NOTE_D4, 16,  NOTE_F4, 16,  NOTE_G4, 12,
  

  NOTE_D4, 12,  NOTE_D4, 12,  NOTE_D5, 12,  REST, 16,  NOTE_A4, 8,
  REST, 12,
  NOTE_GS4, 8,  REST, 16,  NOTE_G4, 12,  REST, 16,  NOTE_F4, 8,  REST, 20,  NOTE_D4, 16,  NOTE_F4, 16,  NOTE_G4, 12,

  NOTE_C4, 12,  NOTE_C4, 12,  NOTE_D5, 12,  REST, 16,  NOTE_A4, 8,
  REST, 12, 
  NOTE_GS4, 8,  REST, 16,  NOTE_G4, 12,  REST, 16,  NOTE_F4, 8,  REST, 20,  NOTE_D4, 16,  NOTE_F4, 16,  NOTE_G4, 12,

  NOTE_B3, 12,  NOTE_B3, 12,  NOTE_D5, 12,  REST, 16,  NOTE_A4, 8,
  REST, 12,
  NOTE_GS4, 8,  REST, 16,  NOTE_G4, 12,  REST, 16,  NOTE_F4, 8,  REST, 20,  NOTE_D4, 16,  NOTE_F4, 16,  NOTE_G4, 12,

  NOTE_AS3, 8,  NOTE_AS3, 8,  NOTE_D5, 12,  NOTE_A4, 8,
  REST, 12,
  NOTE_GS4, 8,  REST, 16,  NOTE_G4, 12,  REST, 16,  NOTE_F4, 8,  REST, 20,  NOTE_D4, 16,  NOTE_F4, 16,  NOTE_G4, 12,
  

  NOTE_D4, 12,  NOTE_D4, 12,  NOTE_D5, 12,  REST, 16,  NOTE_A4, 8,
  REST, 12,
  NOTE_GS4, 8,  REST, 16,  NOTE_G4, 12,  REST, 16,  NOTE_F4, 8,  REST, 20,  NOTE_D4, 16,  NOTE_F4, 16,  NOTE_G4, 12,

  NOTE_C4, 12,  NOTE_C4, 12,  NOTE_D5, 12,  REST, 16,  NOTE_A4, 8,
  REST, 12, 
  NOTE_GS4, 8,  REST, 16,  NOTE_G4, 12,  REST, 16,  NOTE_F4, 8,  REST, 20,  NOTE_D4, 16,  NOTE_F4, 16,  NOTE_G4, 12,

  NOTE_B3, 12,  NOTE_B3, 12,  NOTE_D5, 12,  REST, 16,  NOTE_A4, 8,
  REST, 12,
  NOTE_GS4, 8,  REST, 16,  NOTE_G4, 12,  REST, 16,  NOTE_F4, 8,  REST, 20,  NOTE_D4, 16,  NOTE_F4, 16,  NOTE_G4, 12,

  NOTE_AS3, 8,  NOTE_AS3, 8,  NOTE_D5, 12,  REST, 16,  NOTE_A4, 8,
  REST, 12,
  NOTE_GS4, 8,  REST, 16,  NOTE_G4, 12,  REST, 16,  NOTE_F4, 8,  REST, 20,  NOTE_D4, 16,  NOTE_F4, 16,  NOTE_G4, 12,
  


  NOTE_F4, 16,  REST, 12,  NOTE_F4, 12,  NOTE_F4, 12,  REST, 16,  NOTE_F4, 12,  REST, 16,  NOTE_F4, 12,  REST, 16,  NOTE_D4, 12,
  REST, 16,
  NOTE_D4, 12,  REST, 12,  NOTE_D4, 4,  REST, 16,  NOTE_F4, 12,  NOTE_F4, 12,  NOTE_F4, 12,  NOTE_F4, 12,  REST, 16,  NOTE_G4, 16,
  NOTE_GS4, 12,  REST, 16,  NOTE_G4, 12,  NOTE_F4, 8,  NOTE_D4, 12,  NOTE_F4, 12,  NOTE_G4, 8,


  NOTE_F4, 12,  REST, 16,  NOTE_F4, 12,  NOTE_F4, 12,  REST, 16,
  NOTE_G4, 12,  NOTE_GS4, 8, 
  REST, 16,  NOTE_A4, 12,  REST, 16,  NOTE_C5, 12,  REST, 12,  NOTE_A4, 12,  REST, 12,  NOTE_D5, 12,  REST, 16,  NOTE_D5, 12,
  REST, 16,  NOTE_D5, 12,  NOTE_A4, 12,  NOTE_D5, 12,  NOTE_C5, 4,

  REST, 2,

  NOTE_A4, 12,  REST, 16,  NOTE_A4, 12,  NOTE_A4, 12,  REST, 16,  NOTE_A4, 12,  REST, 16,  
  NOTE_A4, 12,  REST, 16,  NOTE_G4, 12,  REST, 16,  NOTE_G4, 12,  REST, 4,  NOTE_A4, 12,  REST, 16,  NOTE_A4, 12,  NOTE_A4, 12,
  REST, 16,  NOTE_A4, 12,  REST, 16,  NOTE_G4, 12,  REST, 16,
  NOTE_A4, 12,  REST, 16,  NOTE_D5, 12,  REST, 16,  NOTE_A4, 12,  REST, 16,  NOTE_G4, 12,  REST, 16,  NOTE_D5, 12,  REST, 16,
  NOTE_A4, 12,  REST, 16,  NOTE_G4, 12,  REST, 16,  NOTE_F4, 12,  REST, 16,  NOTE_C5, 12,  REST, 16,  NOTE_A4, 12,
  REST, 16,  NOTE_G4, 12,  REST, 16,  NOTE_F4, 12,  REST, 16,  NOTE_D4, 12,  REST, 16,  NOTE_E4, 12,  NOTE_F4, 12,  REST, 16,
  NOTE_A4, 12,  REST, 16,  NOTE_C5, 12,
  
  REST, 2,

  NOTE_F4, 12,  NOTE_D4, 12,  NOTE_F4, 12,  NOTE_G4, 12,  NOTE_GS4, 12,  NOTE_G4, 12,  NOTE_F4, 12,  NOTE_D4, 12,  NOTE_GS4, 12,
  NOTE_G4, 12,  NOTE_F4, 12,  NOTE_D4, 12,  NOTE_F4, 12,  NOTE_G4, 12,
  
  REST, 2,

  NOTE_GS4, 12,  REST, 16,  NOTE_A4, 12,  NOTE_C4, 12,  REST, 16,  NOTE_A4, 12,  NOTE_GS4, 12,  NOTE_G4, 12,  NOTE_F4, 12,
  NOTE_D4, 12,  NOTE_F4, 12,  REST, 16,  NOTE_G4, 12,  NOTE_GS4, 12,  REST, 16,  NOTE_C5, 12,  REST, 12,  NOTE_CS5, 12,  REST, 16,
  NOTE_GS4, 12,  REST, 16,  NOTE_GS4, 12,  NOTE_G4, 12,  NOTE_F4, 12,  NOTE_G4, 12,
  
  REST, 2,

  NOTE_F3, 12,  REST, 16,  NOTE_G3, 12,  REST, 16,  NOTE_A3, 12,  REST, 16,  NOTE_F4, 12,  REST, 16,  NOTE_E4, 10,  REST, 16,
  NOTE_D4, 10,  REST, 16,  NOTE_E4, 10,  REST, 16,  NOTE_F4, 10,  REST, 16,  NOTE_G4, 10,  REST, 16,  NOTE_E4, 10,
  NOTE_A4, 4,
  
  REST, 2,
  
  NOTE_A4, 12,  NOTE_GS4, 12,  NOTE_G4, 12,  NOTE_FS4, 12,  NOTE_F4, 12,  NOTE_E4, 12,  NOTE_DS4, 12,  NOTE_D4, 12,
  NOTE_CS4, 8,  REST, 8,  NOTE_DS4, 8,
  
  REST, 2,

  NOTE_F4, 12,  NOTE_D4, 12,  NOTE_F4, 12,  NOTE_G4, 12,  NOTE_GS4, 12,  NOTE_G4, 12,  NOTE_F4, 12,  NOTE_D4, 12,  NOTE_GS4, 12,
  NOTE_G4, 12,  NOTE_F4, 12,  NOTE_D4, 12,  NOTE_F4, 12,  NOTE_G4, 12,
  
  REST, 2,

  NOTE_GS4, 12,  REST, 16,  NOTE_A4, 12,  NOTE_C4, 12,  REST, 16,  NOTE_A4, 12,  NOTE_GS4, 12,  NOTE_G4, 12,  NOTE_F4, 12,
  NOTE_D4, 12,  NOTE_F4, 12,  REST, 16,  NOTE_G4, 12,  NOTE_GS4, 12,  REST, 16,  NOTE_C5, 12,  REST, 12,  NOTE_CS5, 12,  REST, 16,
  NOTE_GS4, 12,  REST, 16,  NOTE_GS4, 12,  NOTE_G4, 12,  NOTE_F4, 12,  NOTE_G4, 12,
  
  REST, 2,

  NOTE_F3, 12,  REST, 16,  NOTE_G3, 12,  REST, 16,  NOTE_A3, 12,  REST, 16,  NOTE_F4, 12,  REST, 16,  NOTE_E4, 10,  REST, 16,
  NOTE_D4, 10,  REST, 16,  NOTE_E4, 10,  REST, 16,  NOTE_F4, 10,  REST, 16,  NOTE_G4, 10,  REST, 16,  NOTE_E4, 10,
  NOTE_A4, 4,
  
  REST, 2,
  
  NOTE_A4, 12,  NOTE_GS4, 12,  NOTE_G4, 12,  NOTE_FS4, 12,  NOTE_F4, 12,  NOTE_E4, 12,  NOTE_DS4, 12,  NOTE_D4, 12,
  NOTE_CS4, 8,  REST, 8
};

// sizeof gives the number of bytes, each int value is composed of two bytes (16 bits)
// there are two values per note (pitch and duration), so for each note there are four bytes
int notes=sizeof(melody)/sizeof(melody[0])/2; 

// this calculates the duration of a whole note in ms (60s/tempo)*4 beats
int wholenote = (60000 * 4) / tempo;

int divider = 0, noteDuration = 0;

void setup() {
  // iterate over the notes of the melody. 
  // Remember, the array is twice the number of notes (notes + durations)
  for (int thisNote = 0; thisNote < notes * 2; thisNote = thisNote + 2) {

    // calculates the duration of each note
    divider = melody[thisNote + 1];
    if (divider > 0) {
      // regular note, just proceed
      noteDuration = (wholenote) / divider;
    } else if (divider < 0) {
      // dotted notes are represented with negative durations!!
      noteDuration = (wholenote) / abs(divider);
      noteDuration *= 1.5; // increases the duration in half for dotted notes
    }

    // we only play the note for 90% of the duration, leaving 10% as a pause
    tone(buzzer, melody[thisNote], noteDuration*0.9);

    // Wait for the specief duration before playing the next note.
    delay(noteDuration);
    
    // stop the waveform generation before the next note.
    noTone(buzzer);
  }
}

void loop() {
  // no need to repeat the melody.
}

Info

New_song_generation

HI, I really like your repo, can you provide further details about how can we start doing it on our own for any other songs? that will be really helpful to everyone.

So great thank you

NOTE_C2,4, NOTE_G2,3, NOTE_C3,8, NOTE_AS2,3, NOTE_A2,16 ,NOTE_G2,16, NOTE_A2,4, NOTE_G2,8, NOTE_F2,8, NOTE_G2,2, NOTE_G2,16, NOTE_G2,16, NOTE_G2,16,

Back to the future first notes ;-) ;-)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.