     Serial.println("cm");
   }
   
-  // Check to see if it's time for another soanr servo move.
-  if (millis_now - servo_last > servo_delay) {
-    // Remember when this move was done, so we know when to do the next one.
-    servo_last = millis_now;
-    
-    // Sweep
-    // Get the last angle the servo was set to.
-    int servo_pos = servo.read();
-    if (servo_sweep_direction == 0) {
-      servo_pos++; // Add 1 degree to the servo's position.
-    } else {
-      servo_pos--; // Remove 1 degree to the servo's position.
-    }
-    
-    // At the end of the sweep, change directions for the next move.
-    if (servo_pos == 170) {
-      servo_sweep_direction = 1;
-    } else if (servo_pos == 10) {
-      servo_sweep_direction = 0;
-    }
-    servo.write(servo_pos); 
+  // Check to see if it's time for another melody.
+  if (millis_now - melody_last > melody_delay) {
+    // Remeber when this ping was done, so we know when to do the next one.
+    melody_last = millis_now;
+    playMelody();
   }
   
 }
 
+void playMelody() {
+  // iterate over the notes of the melody:
+  for (int thisNote = 0; thisNote < 8; thisNote++) {
+
+    // to calculate the note duration, take one second 
+    // divided by the note type.
+    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
+    int noteDuration = 1000/noteDurations[thisNote];
+    NewTone(tone_pin, melody[thisNote],noteDuration);
+
+    // to distinguish the notes, set a minimum time between them.
+    // the note's duration + 30% seems to work well:
+    int pauseBetweenNotes = noteDuration * 1.30;
+    delay(pauseBetweenNotes);
+    // stop the tone playing:
+    noNewTone(tone_pin);
+  }
+}
+

/**
 HC-SR04 Ultrasonic Range Finder attached to the servo.
 Two motors attached to the motor shield.
 */

#include <NewPing.h> // From https://code.google.com/p/arduino-new-ping/
#include <Servo.h>

// Motor attached to channel A:
const byte motorA_direction = 12;

  digitalWrite(motorB_brake, LOW);   // Disengage the Brake for Channel B
  
  
  // Turn in place constantly.
  digitalWrite(motorA_direction, HIGH); // Channel A forward
  digitalWrite(motorB_direction, LOW); // Channel B backward
  analogWrite(motorA_pwm, 255); // Channel A at max speed 
  analogWrite(motorB_pwm, 255); // Channel B at max speed
  
  playMelody();
}

void loop() {
