MsTimer2 + Led

Hello, sorry for my English.
I'm new in arduino world.
I'm making a project, and i need this loop:

500ms LED On (PIN 13)
4500ms LED off (PIN 13)
500ms LED On (PIN 13)
4500ms LED off (PIN 13)
...and always the same...

I used "delay"command but the time is not exact....so, im trying use "MsTimer2 Library" but i don't understand how can i use that.

I have this code from arduino webpage, could you help me to modify.
Thanks a lot!

// Toggle LED on pin 13 each second
#include <MsTimer2.h>

void flash() {
static boolean output = HIGH;

digitalWrite(13, output);
output = !output;
}

void setup() {
pinMode(13, OUTPUT);

MsTimer2::set(500, flash); // 500ms period
MsTimer2::start();
}

void loop() {
}

When i write:

digitalWrite(13, LOW);

delay(4500);

digitalWrite(13, HIGH);

delay(500);

2 minutes after, the light of my led is totally desynchronized with my guitar metronome. Why?
I used 2 different metronomes, and im sure the problem is in arduino....

Could you modify the code with MsTimer2 to fix it.

Thank so much.

Thank for your reply.
I´m using http://a.bestmetronome.com, is an online metronome,
I´m using too one app for my iphone,
And i´m using too my hand clock....all are perfect, all except the arduino time...and i'm desperate.
I think the problem is in my code...I can´t believe the arduino is not accurate in only 2 minutes...
What do you think?

Thanks so much for your reply.
I understand, but i made months ago the same project with Lego Mindstorms, and i did it without problems...the project was very very easy...but Lego was a toy, so i decided change to Arduino, and i have sold my Lego.

Now i need this led blinking , and a cannot made with arduino..I can believe it!

Only for curiosity, please, could you write me the code with MsTimer2? Please.
I have read that "delay" command is not good.
I have read that MsTimer2, millis and other options are better, but i don't understand to write the code.

Thanks a lot.

i will read it another one. :confused:
Thanks a lot.

Try this simple sketch, play with flashEnd and timeEnd values, maybe you can get a "good enough" sync.

uint32_t timeStart;
int flashEnd = 500, // adjust +/- to sync
    timeEnd = 5000; // adjust +/- to sync

void setup() {
  Serial.begin(9600);
  pinMode(13,OUTPUT);
  
}

void loop() {
  if(millis() - timeStart < flashEnd)
    digitalWrite(13,HIGH);
    else digitalWrite(13,LOW);
  if(millis() - timeStart >= timeEnd)
    timeStart += timeEnd;  
}

Im going to buy the DS3231 RTC for fix the problem, because the internal clock from arduino is not too accurate...it fails 52 secs in only 8 hours!!

Thanks a lot!