7 Segment LED Displaydriver, I2C interface, SAA1064

Dependents:   812_hello

Revision:
1:79cb73f852da
Parent:
0:48adc4a70511
--- a/SAA1064.h	Sun Sep 08 22:23:52 2013 +0000
+++ b/SAA1064.h	Tue Sep 10 19:59:35 2013 +0000
@@ -8,6 +8,37 @@
 #ifndef _SAA1064_H
 #define _SAA1064_H
 
+/** Driver for SAA1064 I2C 4-Digit 7-Segment LED Driver
+ *
+ * @code
+ * #include "mbed.h"
+ * #include "SAA1064.h"
+ * 
+ * // I2C Communication
+ * I2C i2c_lcd(p28,p27); // SDA, SCL for LPC1768
+ * //I2C i2c_lcd(P0_10,P0_11); // SDA, SCL for LPC812
+ *
+ * SAA1064 LED(&i2c_lcd); // I2C bus, Default SAA1064 Slaveaddress
+ * 
+ * int main() {
+ *   uint8_t count = 0; 
+ *
+ *   // Display 0, 1, 2, 3
+ *   LED.write(SAA1064_SEGM[0], SAA1064_SEGM[1], SAA1064_SEGM[2], SAA1064_SEGM[3]);
+ *   wait(1);    
+ *   
+ *   while(1) {
+ *     wait(0.3);    
+ *     count++;       
+ *   
+ *     LED.writeInt(-150 + count, 3, false);  // Display value, dont suppress leading zero's
+ *   }
+ *  
+ * }
+ * @endcode
+ */
+
+
 //Address Defines for SAA1064
 #define SAA1064_SA0 0x70
 #define SAA1064_SA1 0x72
@@ -53,50 +84,89 @@
 #define D_L7                 0x80
 
 //Defines for Segments
-const char SAA1064_SEGM[] = {0x3F,  //0
-                             0x06,  //1
-                             0x5B,  //2
-                             0x4F,  //3
-                             0x66,  //4
-                             0x6D,  //5
-                             0x7D,  //6
-                             0x07,  //7
-                             0x7F,  //8
-                             0x6F,  //9
-                             0x77,  //A
-                             0x7C,  //B
-                             0x39,  //C
-                             0x5E,  //D
-                             0x79,  //E
-                             0x71}; //F
+const uint8_t SAA1064_SEGM[] = {0x3F,  //0
+                                0x06,  //1
+                                0x5B,  //2
+                                0x4F,  //3
+                                0x66,  //4
+                                0x6D,  //5
+                                0x7D,  //6
+                                0x07,  //7
+                                0x7F,  //8
+                                0x6F,  //9
+                                0x77,  //A
+                                0x7C,  //B
+                                0x39,  //C
+                                0x5E,  //D
+                                0x79,  //E
+                                0x71}; //F
 
-#define SAA1064_DP           0x80   //Decimal Point
-#define SAA1064_MINUS        0x40   //Minus Sign
-#define SAA1064_BLNK         0x00   //Blank Digit
-#define SAA1064_ALL          0xFF   //All Segments On
+#define SAA1064_DP              0x80   //Decimal Point
+#define SAA1064_MINUS           0x40   //Minus Sign
+#define SAA1064_BLNK            0x00   //Blank Digit
+#define SAA1064_ALL             0xFF   //All Segments On
                
 
-/** Create an SAA1064 object connected to the specified I2C object and using the specified deviceAddress
+
+
+/** Create an SAA1064 object connected to the specified I2C bus and deviceAddress
  *
- * @param I2C &i2c the I2C port to connect to 
- * @param char deviceAddress the address of the SAA1064
 */
 class SAA1064 {
 public:
-  SAA1064(I2C *i2c, char deviceAddress = SAA1064_SA0);
-  char read();
-  void write(char byte);
-    
-  void setIntensity(unsigned char intensity);
+  /** Create a SAA1064 LED displaydriver object using a specified I2C bus and slaveaddress
+   *
+   * @param I2C &i2c the I2C port to connect to 
+   * @param char deviceAddress the address of the SAA1064
+  */  
+  SAA1064(I2C *i2c, uint8_t deviceAddress = SAA1064_SA0);
+  
+  /** Set segment brightness
+   *
+   * @param intensity       intensity value, valid Range between 0-7, 0 = 0 mA/segment, 1 = 3 mA/segment etc 
+  */  
+  void setIntensity(uint8_t intensity);
+
+
+/** Write digits 
+  *
+  * @param digit1  LED segment pattern for digit1 (MSB) 
+  * @param digit2  LED segment pattern for digit2 
+  * @param digit3  LED segment pattern for digit3
+  * @param digit4  LED segment pattern for digit4 (LSB)       
+  */  
+  void write(uint8_t digit1, uint8_t digit2, uint8_t digit3, uint8_t digit4);        
 
-  void write(unsigned char digit1, unsigned char digit2, unsigned char digit3, unsigned char digit4);        
+/** Write Integer 
+  *
+  * @param value     integer value to display, valid range -999...9999 
+  * @param dp_digit  digit where decimal point is set, valid range 1..4 (no DP shown for dp_digit = 0)
+  * @param leading   suppress leading zero (false=show leading zero, true=suppress leading zero)
+  */  
+  void writeInt(int value, uint8_t dp_digit=0, bool leading=true);
 
-  void writeInt(int value, unsigned char dp_digit=0, bool leading=true);
 
+/** snake: show a short animation
+  *
+  * @param count     number of times animation is repeated, valid range 0..15 
+  *
+  */  
+  void snake(uint8_t count);        
+
+/** splash: show a short animation
+  *
+  * @param count     number of times animation is repeated, valid range 0..15 
+  *
+  */  
+  void splash (uint8_t count);  
+  
 protected:
-  I2C *_i2c;
-  unsigned char _slaveAddress;    
+  I2C *_i2c;                    //I2C bus reference
+  uint8_t _slaveAddress;        //I2C Slave address of device
 
+/** Initialise LED driver 
+  *
+  */  
   void _init(); 
 };