adjusting speed of servo motor

Hi guys,

I’m working with a code to open a box.
I’m using a servo for this code.
But i’m having trouble adjusting the code into the right speed.
I already changed the delay of the servo into a high number but that didn’t work.
Could anybody help me out please?

void setup() {
   myservo.attach(9);
Serial.begin(57600);

for(int i=0;i<MAX_SAMPLES;++i) {
samples[i]=0;
}
for(int i=0;i<MAX_PATTERN;++i) {
pattern[i]=0;
}
}

void loop() {
int volume=analogRead(0);

total -= samples[si];
samples[si] = volume;
total += samples[si];
if( mi < MAX_SAMPLES ) mi++;
si = (si+1) % MAX_SAMPLES;
int average = total / mi;

if( top < average ) top = average;

int x = 10.0 * (float)(average-THRESHOLD)/(float)(top-THRESHOLD);
if(x<0) x=0;
if(x>10) x=10;

if(x>1) {
                                      // noise!
if(is_on==0) {
                                      // noise has just started.
if( c > MINIMUM ) {
                                      // Was the silence a new word or a new letter?
if( c > (AVG_NEWWORD+AVG_SHORT)/2.0 ) {
pattern[pi]=0;
findLetter();
                                      // new word, extra \n
Serial.println();
                                      // start counting - and . all over again.
pi=0;
} else if( c > (AVG_LONG+AVG_SHORT)/2.0 ) {
pattern[pi]=0;
findLetter();
                                      // start counting - and . all over again.
pi=0;
}

}
                                      // remember noise started
is_on=1;
c=0;
}
} else {
                                      // silence!
if(is_on==1) {
                                      // silence is new
if( c > MINIMUM ) {
                                      // Was the noise a long or a short?
if( c > (AVG_LONG + AVG_SHORT)/2.0 ) {
                                      // long
Serial.print('-');
pattern[pi++]='0';
} else {
                                      // short
Serial.print('.');
pattern[pi++]='1';
}
}
                                      // remember silence started
is_on=0;
c=0;
}
}

c++;

delay(WAIT);
}

                          // pattern contains the received longs and shorts,
                          // saved as 1s and 0s. Find the matching code in the list
                          // then find the matching printable character.
                          // print '?' if nothing is found
void findLetter() {
int i,j;
                          // go through all the codes
for(i=0;i<NUM_CODES;i++) {
                          // check if code[i] matches pattern exactly.
if(strlen(pattern) == strlen(codes[12]) && strcmp(pattern,codes[12])==0) {
                          // match!
Serial.print(' ');
Serial.println(letters[12]);
Serial.print("GELUKT!");

for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  delay(1000);
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(5);                       // waits 15ms for the servo to reach the position
 
}
return;
}
}
}
void setup() {
   myservo.attach(9);
  Serial.begin(57600);
}

void loop() 
{
  int volume=analogRead(0);

  total -= samples[si];
  samples[si] = volume;
  total += samples[si];
  if( mi < MAX_SAMPLES ) mi++;
  si = (si+1) % MAX_SAMPLES;
  int average = total / mi;

  if( top < average ) top = average;

  int x = 10.0 * (float)(average-THRESHOLD)/(float)(top-THRESHOLD);
  if(x<0) x=0;
  if(x>10) x=10;

  if(x>1) {
    // noise!
    if(is_on==0) {
      // noise has just started.
      if( c > MINIMUM ) {
        // Was the silence a new word or a new letter?
        if( c > (AVG_NEWWORD+AVG_SHORT)/2.0 ) {
          pattern[pi]=0;
          findLetter();
          // new word, extra \n
          Serial.println();
          // start counting - and . all over again.
          pi=0;
        } else if( c > (AVG_LONG+AVG_SHORT)/2.0 ) {
          pattern[pi]=0;
          findLetter();
          // start counting - and . all over again.
          pi=0;
        }
      }
      // remember noise started is_on=1;
      c=0;
    }
  } else {
                                      // silence!
    if(is_on==1) {
                                      // silence is new
      if( c > MINIMUM ) {
                                      // Was the noise a long or a short?
        if( c > (AVG_LONG + AVG_SHORT)/2.0 ) {
                                      // long
          Serial.print('-');
          pattern[pi++]='0';
        } else {
                                      // short
          Serial.print('.');
          pattern[pi++]='1';
        }
      }
      // remember silence started is_on=0;
      c=0;
    }
  }

  c++;

  delay(WAIT);
}

// pattern contains the received longs and shorts,
// saved as 1s and 0s. Find the matching code in the list
// then find the matching printable character.
// print '?' if nothing is found
void findLetter() {
  int i,j;
  // go through all the codes
  for(i=0;i<NUM_CODES;i++) {
                          // check if code[i] matches pattern exactly.
    if(strlen(pattern) == strlen(codes[12]) && strcmp(pattern,codes[12])==0) {
                          // match!
      Serial.print(' ');
      Serial.println(letters[12]);
      Serial.print("GELUKT!");

      for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
        // in steps of 1 degree
        myservo.write(pos);              // tell servo to go to position in variable 'pos'
        delay(15);                       // waits 15ms for the servo to reach the position
      }
      delay(1000);
      for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
        myservo.write(pos);              // tell servo to go to position in variable 'pos'
        delay(5);                       // waits 15ms for the servo to reach the position
      }
      return;
    }
  }
}

But i'm having trouble adjusting the code into the right speed.

90% of that code has NOTHING to do with moving a servo at a specific speed. Get rid of the useless code until the servo does move properly.

Whining "it doesn't work", without saying what actually happens, and what you expected, was a waste of time - your and ours.

I already changed the delay of the servo into a high number but that didn’t work.

Which of the delay()s did you change ? The ones in the for loops or the one between the for loops ?