 #define CLOCK_MODE  1
 #define NIGHTLIGHT_MODE 2
 
-int mode = BACKLIGHT_MODE;
+#define MODE_SWITCH_PIN 10
+int mode = CLOCK_MODE; // BACKLIGHT_MODE;
+char s[200];
+
+DateTime wakeTime = DateTime( 2016,1,1,17,45); // 5:45am
 
 /*******************************************************************************
 *******************************************************************************/
 void setup() {
+
+  pinMode(MODE_SWITCH_PIN,INPUT_PULLUP);
   
   rtcSetup();
   neoPixelSetup();
   
 }
 
+bool pressed = false;
 /*******************************************************************************
 *******************************************************************************/
 void loop() {
 
-  Serial.print("in loop with mode of");
-  Serial.println(mode);
+  current = rtc.now();
+  
   switch ( mode )
   {
     case BACKLIGHT_MODE:
       backlight();
       break;
     case CLOCK_MODE:
-      clocklight();
+      clocklight(current);
       break;
     case NIGHTLIGHT_MODE:
-      nightlight();
+      nightlight(current);
       break;
   }
-
-}
-
-/*******************************************************************************
-*******************************************************************************/
-void clocklight() 
-{
-}
-
-/*******************************************************************************
-*******************************************************************************/
-void nightlight() 
-{
-
-}
-
-/*******************************************************************************
-*******************************************************************************/
-void backlight() 
-{
-
+  
+  if ( digitalRead(MODE_SWITCH_PIN) == LOW )
+  {
+    if ( !pressed )
+    {
+      pressed = true;
+      mode++;
+      if ( mode > NIGHTLIGHT_MODE )
+        mode = BACKLIGHT_MODE;
+      
+      Serial.print("Switching mode to ");
+      Serial.println(mode);
+      clearPixels();
+    }
+  }
+  else
+    pressed = false;
+}
+
+int sec = 0;
+int min = 0;
+int hr = 0;
+
+void clearPixels()
+{
+  for ( int i = 0; i < NEOPIXEL_LEDS; i++ )
+    strip.setPixelColor(i,0);
+}
+/*******************************************************************************
+*******************************************************************************/
+void clocklight(DateTime current) 
+{
+  strip.setPixelColor(sec,0);
+  strip.setPixelColor(min,0);
+  strip.setPixelColor(hr,0);
+  
+  sec = current.second() / 5;
+  min = current.minute() / 5;
+  hr = current.hour() % 12;
+  
+  strip.setPixelColor(sec,secColor);
+  strip.setPixelColor(min,minColor);
+  strip.setPixelColor(hr,hrColor);
+
+  if ( sec == min && sec == hr )
+    strip.setPixelColor(sec,secColor | minColor | hrColor );
+  else if ( sec == min )
+    strip.setPixelColor(sec,secColor | minColor);
+  else if ( sec == hr )
+    strip.setPixelColor(sec,secColor | hrColor);
+  else if ( min == hr )
+    strip.setPixelColor(min,minColor | hrColor);
+  
+  strip.show();
+  
+  sprintf( s, "%d:%d:%d - %d %d %d", current.hour(), current.minute(), current.second(), hr,min,sec);
+  Serial.println(s);  
+}
+
+int prevHours = -1;
+
+/*******************************************************************************
+*******************************************************************************/
+void nightlight(DateTime current) 
+{
+  // how many hours until wakey?
+  double currentMin = 60.0*current.hour() + current.minute();
+  double wakeyMin = 60.0*wakeTime.hour() + wakeTime.minute();
+
+  double diffMin = wakeyMin - currentMin;
+  if ( diffMin < 0 ) 
+    diffMin = wakeyMin + (24.0*60)-currentMin; // remains of today + until wakey
+  int newHours = (diffMin / 60)+.5;
+  if ( newHours > 12 )
+    newHours = 12;
+    
+  bool show = checkColorChange();
+  
+  if ( prevHours != newHours || show )
+  {
+    show = true;
+    if ( prevHours >= 0 )
+      strip.setPixelColor(prevHours,0);
+    for ( int i = 0; i < abs(newHours); i++ )
+      strip.setPixelColor(i,sensorValue);
+    Serial.print( "PreHours ");
+    Serial.print( prevHours );
+    Serial.print( " newHours ");
+    Serial.println( newHours );
+    prevHours = newHours;
+  }
+
+  Serial.print( "Wakey current is ");
+  Serial.print( currentMin );
+  Serial.print( " and wakey is ");
+  Serial.print( wakeyMin );
+  Serial.print( " and diffMin is ");
+  Serial.print( diffMin );
+  Serial.print( " and show is ");
+  Serial.println( show );
+  delay(500);
+
+  if ( show )
+    strip.show();
+}
+
+bool checkColorChange()
+{
   // read the analog in value:
   byte newSensorValue = map(analogRead(ANALOG_COLOR_PIN), 0, 1023, 0, 255);
   bool updateNeo = false;

      sensorValue = newSensorValue;
      updateNeo = true;
  }
  float newSensorBrightness = map(analogRead(ANALOG_BRIGHTNESS_PIN), 0, 1023, 0, 255);
  
  if (  brightnessValue != newSensorBrightness )
  {
      updateNeo = true;

      strip.setBrightness(brightnessValue);
  }
  
  return updateNeo;  
}

/*******************************************************************************
*******************************************************************************/
void backlight() 
{
  if ( checkColorChange() )
  {
    colorWipe(Wheel(sensorValue),SWIPE_WAIT);
  }
