Arduino processor speed

Hi guys, I am currently building an led syncronisation to music system. My problem is That I use the delay() function to sync the leds and somethimes the delays arent axxurate enough to make the effects possible. I wisb to know weather changing my uno to a due would make any difference. If not is there something I could do to make my delays acxurate?.

RyanArduino:
Hi guys, I am currently building an led syncronisation to music system. My problem is That I use the delay() function to sync the leds and somethimes the delays arent axxurate enough to make the effects possible.

delay() is the devil's function. Stop using it.

RyanArduino:
I wisb to know weather changing my uno to a due would make any difference.

No.

RyanArduino:
If not is there something I could do to make my delays acxurate?.

Yes, but it's impossible to say what to do without seeing the code.

What are you using the delays to do?

Have you tried delayMicroseconds?

Ok so when i start the music using my laptop i push the button and the synchronized led show starts. this is a small example. but even though i know the math in the delays is correct the first led will light on time but the rest seam to miss by a half a second.

const int buttonPin = 2;     // the number of the pushbutton pin



int buttonState = 0;         
void setup() {
  // initialize the LED pins as an output:
  pinMode(0, OUTPUT);
  pinMode(1, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);     
}

void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  // button is pushed when music starts.
  if (buttonState == HIGH) {     
    delay(456);    
    digitalWrite(0, HIGH);
    delay(100);
    digitalWrite(0, LOW);
    delay(789);
    digitalWrite(1, HIGH);
    delay(100);
    digitalWrite(1, LOW);
    delay(656);    
    digitalWrite(2, HIGH);
    delay(100);
    digitalWrite(2, LOW);
    delay(3789);
    digitalWrite(3, HIGH);
    delay(100);
    digitalWrite(3, LOW);
    delay(866);    
    digitalWrite(4, HIGH);
    delay(100);
    digitalWrite(4, LOW);
    delay(689);
    digitalWrite(5, HIGH);
    delay(100);
    digitalWrite(5, LOW);
      
  } 
  else {
    // turn LED off:
    digitalWrite(0, LOW); 
    digitalWrite(1, LOW); 
    digitalWrite(3, LOW); 
    digitalWrite(4, LOW); 
    digitalWrite(5, LOW); 
    
  }
}

THANKYOU.

Seems like you are trying to time this with music. Timing things with delay functions is tough. Now that I've seen your delay times, I would NOT suggest using delayMicroseconds() as its only accurate up to ~16 milliseconds.

For this amount of time, it seems like the delay function should serve you well enough to keep synced.

Are you taking into account the 100ms delays you have between turning the LED on and off?

Are you also taking into account the delay you as a human has between when you hear the music and when you press the button?

You can always just try manually adjusting all of the delays in your code until the LEDs match up with the music.

Hi,
yes i have been taking into consideration the 100 ms to switch off. do you think there is something else i could do, maybe make the arduino start the music or something like that?