Commits

Trammell Hudson committed 5b71b83

Pulsing nightlight

Comments (0)

Files changed (1)

alphaclock_18_Rev1_0/alphaclock_18_Rev1_0.pde

 byte ExtRTC;
 
 
-// Ramp the nightlight up for three seconds, and then fade over one second.
-void updateNightLight()
+/** Ramp the nightlight similar to the Adafruit breathing cufflinks.
+ */
+static void
+nightlight_update()
 {
-  analogWrite(14, (SecNow % 4) * 64);
+	static uint8_t value;
+	static uint8_t sign;
+
+	if (sign)
+	{
+		if (++value == 0xFF)
+			sign = 0;
+	} else {
+		if (--value == 0x00)
+			sign = 1;
+	}
+
+	analogWrite(14, value);
 }
 
 
 
   EEReadSettings();   // Read stored settings from EEPROM.
 
-  updateNightLight();
+  nightlight_update();
 
 
   VCRmode = 1;  // Time is NOT yet set.
 
 
   millisCopy = millis();
+	nightlight_update();
 
   PINBcopy = PINB & buttonmask;
 
             else
               NightLightType = 0;
 
-            updateNightLight();
+            nightlight_update();
           }
           else if (OptionMode == 3) {
             if (AlarmTone < 3)
               NightLightType--;
             else
               NightLightType = 2;
-            updateNightLight();
+            nightlight_update();
           }
           else if (OptionMode == 3) {
             if (AlarmTone > 0)