Commits

Trammell Hudson committed a3a9b18

Add chasers and replace macros with inlines

Comments (0)

Files changed (1)

alphaclock_18_Rev1_0/alphaclock_18_Rev1_0.pde

 #include <avr/pgmspace.h>
 
 
-#define AllLEDsOff();  PORTA |= 127;  
+static inline void
+AllLEDsOff(void)
+{
+  PORTA |= 0x7F;
+}
 
 // The buttons are located at PB0, PB1, PB2, PB3
 #define buttonmask 15 
 	0x000c, // _
 	0x0400, // `
 
-        // Spinners
+        // Spinners rotate through the middle
         1 << 0xB,
         1 << 0xC,
         1 << 0x5,
         1 << 0xF,
         1 << 0x4,
         1 << 0xA,
+        
+        // Chaser goes around the outside of the box
+        1 << 0,
+        1 << 1,
+        1 << 6,
+        1 << 7,
+        1 << 3,
+        1 << 2,
+        1 << 8,
+        1 << 9,
 };
 
 // Starting offset of our ASCII array:
 // Starting offset for number zero
 #define numberOffset 16
 
+#define cbi(PORT, BIT) do { (PORT) &= ~(1 << (BIT)); } while(0)
+#define sbi(PORT, BIT) do { (PORT) |=   1 << (BIT); } while(0)
+#define bit_is_clear(PORT, BIT) (!bit_is_set(PORT, BIT))
+#define bit_is_set(PORT, BIT) ((PORT) & (1 << (BIT)))
 
 //Faster latch macro!
-#define Latch();    PORTC |= 4;PORTC &= 251;    
-
-
-void AlphaWrite (byte l1, byte h1, byte h2)
-{  // Transmit data to to LED drivers through SPI
-  PORTA |= 127; // Blank all character "rows" (A0-A5) and LED driver
-  SPDR = l1;
-  while (!(SPSR & _BV(SPIF))) {
-  }  //Wait for transmission complete
-  SPDR = h1;
-  while (!(SPSR & _BV(SPIF))) {
-  }  //Wait for transmission complete
-  SPDR = h2;
-  while (!(SPSR & _BV(SPIF))) {
-  }  //Wait for transmission complete
+static inline void
+Latch(void)
+{
+    sbi(PORTC, 2);
+    cbi(PORTC, 2);
 }
 
+/** Blocking send a byte via SPI */
+static inline void
+spi_write(
+  const byte b
+)
+{
+  SPDR = b;
+  while (bit_is_clear(SPSR, SPIF))
+    ;
+}
+
+
+/* Send the three byte command to the LED driver via SPI.
+ * Blocks until it is done.
+ */
+void
+AlphaWrite(byte l1, byte h1, byte h2)
+{
+  AllLEDsOff();
+  spi_write(l1);
+  spi_write(h1);
+  spi_write(h2);
+}
 
 
 byte OptionMode;    // Are we in the settings menu?   If so, what position?
 
 void updateNightLight()
 {
-
-  if (NightLightType == 0)
-    analogWrite(14, 0);   
-  if (NightLightType == 1)
-    analogWrite(14, 60);  
-  if (NightLightType == 2)
-    analogWrite(14, 255);  
-
+  analogWrite(14, SecNow * 4);
 }
 
 
     else {
       // "Normal" time display: 
       //CharacterBuffer[0] = (AMPM24HdisplayNow - asciiOffset);
-      CharacterBuffer[0] = (SecNow % 8) + 1 + '`' - asciiOffset; // spinner
+      //CharacterBuffer[0] = (SecNow % 8) + 1 + '`' - asciiOffset; // spinner
+      CharacterBuffer[0] = (SecNow % 8) + 1 + 8  + '`' - asciiOffset; // chaser     
       CharacterBuffer[1] = (MinNowOnes + numberOffset);
       CharacterBuffer[2] = (MinNowTens + numberOffset);
       CharacterBuffer[3] = (HrNowOnes + numberOffset);