button switch sensor program—need urgent help!

I have a sharp IR sensor, a push button and some LEDs connected to my arduino. I'm trying to write a program in which the sensor collects data and sends it to the LEDs, but the user has the option of turning off the lights entirely using a push-button switch. I also want to create an option using another push-button in which the user can press it and the LEDs will retain that particular brightness. Basically, I'm trying to make an LED flashlight in which the user can control the brightness using the sensor.

Here is my code so far. It's a school project, so it's due very soon. Please help me out! Thanks!

int debounce = 10; //length of time to debounce switch in milliseconds
int ButtonValue; //used to feel current button state
int LastButtonValue = LOW; //used to remember last button state
int PushButton = 2;
int led = 9;

double y;
int analogPin = 4;
int val;
//assume unpressed button at startup
int state = LOW;

void setup()
{
pinMode(led, OUTPUT); //sets the LED pin as output
pinMode(PushButton, INPUT); //sets PushButton pin as input
Serial.begin(9600);
}

void loop()
{

ButtonValue = digitalRead(PushButton); //digitally reads value of PushButton into variable ButtonValue
if (ButtonValue == HIGH && LastButtonValue == LOW){
delay(debounce); //wait long enough to know that the input is real
ButtonValue = digitalRead(PushButton);
if (ButtonValue == HIGH && LastButtonValue == LOW){
Serial.print("pressed ");
state = !state;
digitalWrite(led, state); //toggle the LED
Serial.println(state);

if (ButtonValue != LOW){

val = analogRead(analogPin); // read the sensor's data
Serial.print("Analog value =\t");
y = (772.92 * 9.723 * 1/(val))*(5/2.5); //this equation linearizes the sensor data
Serial.println(y);
delay(500);

analogWrite(led, y);
}

}
}
LastButtonValue = ButtonValue; //make a note of the state we're in for
}