I2C controlled 4 digit 7 segment LED display library

Committer:
patthoyts
Date:
Fri Feb 07 00:10:45 2014 +0000
Revision:
0:48b781bee6dc
Initial version of I2C display library.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
patthoyts 0:48b781bee6dc 1 #ifndef _DisplayI2C_h_INCLUDE
patthoyts 0:48b781bee6dc 2 #define _DisplayI2C_h_INCLUDE
patthoyts 0:48b781bee6dc 3
patthoyts 0:48b781bee6dc 4 #include "mbed.h"
patthoyts 0:48b781bee6dc 5 /** The DisplayI2C class provides simplified access to a 4 digit 7 segment LED display
patthoyts 0:48b781bee6dc 6 * over I2C via an MCP23017 port expander
patthoyts 0:48b781bee6dc 7 */
patthoyts 0:48b781bee6dc 8 class DisplayI2C
patthoyts 0:48b781bee6dc 9 {
patthoyts 0:48b781bee6dc 10 public:
patthoyts 0:48b781bee6dc 11 /**
patthoyts 0:48b781bee6dc 12 * @param[in] i2c pass in a reference to the programs I2C instance.
patthoyts 0:48b781bee6dc 13 * @param[in] address I2C address of the MCP device (set by external resistors)
patthoyts 0:48b781bee6dc 14 * @param[in] decimalpoint set the digit to show a decimal point. If set
patthoyts 0:48b781bee6dc 15 * greater than 4 then no decimal point is enabled.
patthoyts 0:48b781bee6dc 16 */
patthoyts 0:48b781bee6dc 17 DisplayI2C(I2C& i2c, uint8_t address, uint8_t decimalpoint = 5);
patthoyts 0:48b781bee6dc 18 /**
patthoyts 0:48b781bee6dc 19 * Call once to initialize the MCP device registers.
patthoyts 0:48b781bee6dc 20 */
patthoyts 0:48b781bee6dc 21 void Setup();
patthoyts 0:48b781bee6dc 22 /**
patthoyts 0:48b781bee6dc 23 * Set the value to be displayed.
patthoyts 0:48b781bee6dc 24 * @param[in] value integer value (0 - 9999)
patthoyts 0:48b781bee6dc 25 */
patthoyts 0:48b781bee6dc 26 void SetValue(int value);
patthoyts 0:48b781bee6dc 27 /**
patthoyts 0:48b781bee6dc 28 * Enable slow flashing of the whole display to indicate an alternate mode
patthoyts 0:48b781bee6dc 29 * @param[in] flashing true to enable flashing mode
patthoyts 0:48b781bee6dc 30 */
patthoyts 0:48b781bee6dc 31 void SetFlashing(bool flashing);
patthoyts 0:48b781bee6dc 32 /**
patthoyts 0:48b781bee6dc 33 * This function must be called at intervals to multiplex to the next digit.
patthoyts 0:48b781bee6dc 34 * Ideally the digits should be updated at 50Hz so this function should be
patthoyts 0:48b781bee6dc 35 * called at 200Hz.
patthoyts 0:48b781bee6dc 36 */
patthoyts 0:48b781bee6dc 37 void Update();
patthoyts 0:48b781bee6dc 38
patthoyts 0:48b781bee6dc 39 private:
patthoyts 0:48b781bee6dc 40 void SetLEDs(uint8_t value);
patthoyts 0:48b781bee6dc 41 void SelectDigit(uint8_t digit);
patthoyts 0:48b781bee6dc 42 I2C & mI2C;
patthoyts 0:48b781bee6dc 43 uint8_t mAddr;
patthoyts 0:48b781bee6dc 44 uint8_t mDigit;
patthoyts 0:48b781bee6dc 45 uint8_t mDP; // Digit with decimal point (>4 to disable)
patthoyts 0:48b781bee6dc 46 bool mFlashing;
patthoyts 0:48b781bee6dc 47 char mValue[5];
patthoyts 0:48b781bee6dc 48 };
patthoyts 0:48b781bee6dc 49
patthoyts 0:48b781bee6dc 50 #endif // _DisplayI2C_h_INCLUDE