Activating a servo, LED and Piezo with a LDR

Hi,
Serious newb here with a serious newb question. First time using the arduino in a college project and my code is just all wrong. Im trying to activate an alarm (ie. a buzzer and Led) while also activating a servo motor to lock to a certain position, using an LDR. Its basically a child lock for when a child goes to open a prohibited cupboard, the LDR reads the light entering and activates the rest. A button is used to arm the alarm. If someone could have a look and see where Im going wrong, that would be fantastic!
Thanks!

#include <Servo.h> 

Servo myservo;
int val;

//Global Variables and constants
const int buttonPin = A0; // button Pin connected to Analog 0
const int buzzerPin = A1; // buzzer Pin connected to Analog 1
const int servoPin = 7; // servo Pin connected to Digital 7



//Alarm LED
const int ledPin = 8; // LED at Digital 8



int tolerance=20; // Sensitivity of the Alarm
boolean calibrated=false; // When accelerometer is calibrated - changes to true 
boolean lightDetected=false; // When motion is detected - changes to true



void setup(){
 //Begin Serial communication
 Serial.begin(38400);
 
 //Initilise LED Pin
 pinMode(ledPin, OUTPUT);
 

}



void loop(){
 {
val = analogRead(0);
val = map(val, 0, 1023, 0, 510);
myservo.write(val);
delay(15);
} 


   if(lightDetected){
  myservo.attach(7);
  myservo.write(180);  // set servo to lock position
} 
 // If motion is detected - sound the alarm !
 if(lightDetected){
 Serial.println("ALARM");
 ALARM();
 delay(1000);
 }









void buzz(int reps, int rate){
 for(int i=0; i<reps; i++){
 analogWrite(buzzerPin,900);
 delay(100);
 analogWrite(buzzerPin,0);
 delay(rate);
 }
}


 // Calibration sequence initialisation sound - 3 seconds before calibration begins
 {buzz(3,1000)
}
{
 //Delay 10msec between readings
 delay(10);
 }
 {
 //End of calibration sequence sound. ARMED.
 buzz(3,40);
 printValues(); //Only useful when connected to computer- using serial monitor.
 calibrated=true;
 
}



//Function used to make the alarm sound, and blink the LED.
void ALARM(){

 //don't check for movement until recalibrated again
 calibrated=false;
 
 // sound the alarm and blink LED
 digitalWrite(ledPin, HIGH);
 buzz(4,20);
 digitalWrite(ledPin, LOW);
}
}
}

You see to be defining the functions buzz() and alarm() inside the function loop(). You are not allowed to do that. Function definitions must be outside every other function. Move the functions out of loop() and see if that solves the problem. If not post the revise version and tell us how it works.

And, while the compiler does not care, it will be much easier to make sense of your code if you take some trouble to indent it properly. At the very least use the AutoFormat option in the IDE editor.

...R