   else if (digitalRead(TimeButton)==LOW && debounceDigitalRead(TimeButton)==LOW) {
     setTime();
   } 
-//  else if (digitalRead(OffButton)==HIGH && debounceDigitalRead(OffButton)==HIGH) {
-//    if (alarmActive) {
-//      alarmActive = false;
-//      alarmEnabled = false;
-//      turnLightOff(lastAlarmLightLevel);
-//      waitForButtonDepress(OffButton);
-//    } 
-//    else if (sunSetActive) {
-//      sunSetActive = false;
-//      turnLightOff(lastSunSetLightLevel);
-//      waitForButtonDepress(OffButton);
-//    }
-//    else {
-//      setSunSet();
-//    }
-//  } 
+  else if (digitalRead(OffButton)==HIGH && debounceDigitalRead(OffButton)==HIGH) {
+    if (alarmActive) {
+      alarmActive = false;
+      alarmEnabled = false;
+      turnLightOff(lastAlarmLightLevel);
+      waitForButtonDepress(OffButton);
+    } 
+    else if (sunSetActive) {
+      sunSetActive = false;
+      turnLightOff(lastSunSetLightLevel);
+      waitForButtonDepress(OffButton);
+    }
+    else {
+      setSunSet();
+    }
+  } 
   updateBrightness();
 //  updateLight();
   updateCurrentTime();

const int minLightLevel = 320;
const int maxLightLevel = 800;

// (a1,b1) -> f_1 -> (a2,b2) -> f_2 -> (a3,b3) -> f_3 -> (a4,b4)
double a1 = 0.0;
double b1 = minLightLevel;
double a2 = thirtyminutes-10*60; // 10 minutes before
double b2 = maxLightLevel*.30; // 30% 
double a3 = thirtyminutes-5*60; // 5 minutes before
double b3 = maxLightLevel*.40; // 40%
double a4 = thirtyminutes;
double b4 = maxLightLevel;

double m1 = (b2-b1)/(a2-a1);
double c1 = (b1-m1*a1);
double m2 = (b3-b2)/(a3-a2);
double c2 = (b2-m2*a2);
double m3 = (b4-b3)/(a4-a3);
double c3 = (b3-m3*a3);

// This function maps the visible range of the LED to the time interval 0 to 1800 seconds.
// Visible range on LED at TimerOne Period of 1000us (1 kHz flicker) is [176,1008] at increment of 16.
// Therefore the two points are (0,176) and (1800,1008) which results in a slope of 0.4622222 and a y-intercept of 176.
// 2014-03-11:  (0,minlightLevel) -> (1800,maxLightLevel), slope = (maxLightLevel-minLightLevel)/1800
int lastAlarmLightLevel = 0;
int32_t linearBright(int32_t level) {
  //int linearLevel = ceil(maxBright*1.0/(1.0+exp(-(level*1.0-maxTime*0.5)/(maxTime/16.0))));
  //int linearLevel = level;
  //int linearLevel = 36.787944117144235*exp(exp(level*0.00075472484480368113));

  // (0,176) -> (1800,1008)
  //int linearLevel = 0.46222222*level + 176; // linear
  //int linearLevel = 176.0*exp(0.000969577*level); // exponential
  //int linearLevel = 64.746781646173858*exp(exp(0.00056103794655312409*level)); // exp(exp())

  //This method seems to work well for MR16 9W LED
  int linearLevel = ((maxLightLevel-minLightLevel)/1800.0)*level+minLightLevel;
  //This method worked well for 10W LED
//  int linearLevel = 0;
//  if (level < a2) {
//    linearLevel = m1*level+c1;
//  } else if (level < a3) {
//    linearLevel = m2*level+c2;
//  } else {
//    linearLevel = m3*level+c3;
//  }
  
  //Serial.print("linearLevel = ");
  //Serial.println(linearLevel);
  lastAlarmLightLevel = linearLevel;
  //timer.pwm(LEDpinA,lastAlarmLightLevel);
  return linearLevel;
}

// DONE:  Update to display 12 hr time

  pinMode(OffButton,INPUT);
  pinMode(AlarmLED, OUTPUT);
  pinMode(TimeLED, OUTPUT);
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
  encoder = new ClickEncoder(ENCODER_PIN0, ENCODER_PIN1, -1, 4);
  Timer1.initialize(1000);
  Timer1.attachInterrupt(timerIsr); 
