#include "pitches.h"

const int piezoPin = 2;

//hedwigs theme
const float semiBreve = 1000;
const float crotchet = semiBreve/3;
const float dCrotchet = semiBreve/2;
const float minum = crotchet * 2;
const float quaver = crotchet/2;

void setup(){
  
}

void loop() {
  delay(1000);
  hedwigsTheme();
  delay(1000);
}

void hedwigsTheme(){
  //first section
  playTone(NOTE_B5, crotchet);

  playTone(NOTE_E6, dCrotchet);
  playTone(NOTE_G6, quaver);
  playTone(NOTE_FS6, crotchet);

  playTone(NOTE_E6, minum);
  playTone(NOTE_B6, crotchet);

  playTone(NOTE_A6, semiBreve);

  playTone(NOTE_FS6, semiBreve);

  playTone(NOTE_E6, dCrotchet);
  playTone(NOTE_G6, quaver);
  playTone(NOTE_FS6, crotchet);

  playTone(NOTE_DS6, minum);
  playTone(NOTE_F6, crotchet);

  playTone(NOTE_B5, semiBreve + minum);
  delay(300);

  //second section
  playTone(NOTE_B5, crotchet);

  playTone(NOTE_E6, dCrotchet);
  playTone(NOTE_G6, quaver);
  playTone(NOTE_FS6, crotchet);

  playTone(NOTE_E6, minum);
  playTone(NOTE_B6, crotchet);

  playTone(NOTE_D7, minum);
  playTone(NOTE_CS7, crotchet);

  playTone(NOTE_C7, minum);
  playTone(NOTE_GS6, crotchet);

  playTone(NOTE_C7, dCrotchet);
  playTone(NOTE_B6, quaver);
  playTone(NOTE_AS6, crotchet);

  playTone(NOTE_AS5, minum);
  playTone(NOTE_G6, crotchet);

  playTone(NOTE_E6, semiBreve + minum);
  delay(300);

  //third section
  playTone(NOTE_G6, crotchet);

  playTone(NOTE_B6, minum);
  playTone(NOTE_G6, crotchet);

  playTone(NOTE_B6, minum);
  playTone(NOTE_G6, crotchet);

  playTone(NOTE_C7, minum);
  playTone(NOTE_B6, crotchet);

  playTone(NOTE_AS6, minum);
  playTone(NOTE_FS6, crotchet);

  playTone(NOTE_G6, dCrotchet);
  playTone(NOTE_B6, quaver);
  playTone(NOTE_AS6, crotchet);

  playTone(NOTE_AS5, minum);
  playTone(NOTE_B5, crotchet);

  playTone(NOTE_B6, semiBreve + minum);
  delay(300);

  //fourth section
  playTone(NOTE_G6, crotchet);

  playTone(NOTE_B6, minum);
  playTone(NOTE_G6, crotchet);

  playTone(NOTE_B6, minum);
  playTone(NOTE_G6, crotchet);

  playTone(NOTE_D7, minum);
  playTone(NOTE_CS7, crotchet);

  playTone(NOTE_C7, minum);
  playTone(NOTE_GS6, crotchet);

  playTone(NOTE_C7, dCrotchet);
  playTone(NOTE_B6, quaver);
  playTone(NOTE_AS6, crotchet);

  playTone(NOTE_AS5, minum);
  playTone(NOTE_G6, crotchet);

  playTone(NOTE_E6, semiBreve + minum);
  delay(300);
}

void playTone(int freq, float noteLength) {
  tone(piezoPin, freq, noteLength);
  delay(noteLength+50);
}