int speakerPin = 5;
char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };

char notes[] = "eeeeeeegcde fffffeeeeddedg";
int beats[] = { 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2};

char kotek [] ="cdeee cdefed";
int miau [] ={4,4,4,2,1,1,1,2,1};

char star [] = " ddggagfeeeaa";
int xxx [] = { 1,1,1,1,1,1,1,1,1,1,1,1 } ;


void playTone(int tone, int duration) {
  for (long i = 0; i < duration * 1000L; i += tone * 2) {
    digitalWrite(speakerPin, HIGH);
    delayMicroseconds(tone);
    digitalWrite(speakerPin, LOW);
    delayMicroseconds(tone);
  }
}
void playNote(char note, int duration) {
    
  // play the tone corresponding to the note name
  for (int i = 0; i < 8; i++) {
    if (names[i] == note) {
      playTone(tones[i], duration);
    }
  }
}

void _piesn (char nuty[], int trwanie [], int rytm, int _dl)
  {for (int i = 0; i < _dl; i++) {
    if (nuty[i] == ' ') {
      delay(trwanie[i] * rytm); // rest
    } else {
      playNote(nuty[i], trwanie[i] * rytm);
    }
    
    // pause between notes
    delay(rytm / 2); 
  }
  }


  
void setup() {
  pinMode(speakerPin, OUTPUT);
}
void loop() {
  _piesn(kotek,miau,100,9);
  delay(1000);
  _piesn(notes,beats,100, 26);
_piesn(notes,beats,500, 26);
 _piesn(star, xxx, 100, 12);
}
