7 Segment LED Displaydriver, I2C interface, SAA1064
Diff: SAA1064.cpp
- Revision:
- 1:79cb73f852da
- Parent:
- 0:48adc4a70511
- Child:
- 2:970360b29a2a
diff -r 48adc4a70511 -r 79cb73f852da SAA1064.cpp --- a/SAA1064.cpp Sun Sep 08 22:23:52 2013 +0000 +++ b/SAA1064.cpp Tue Sep 10 19:59:35 2013 +0000 @@ -8,30 +8,24 @@ #include "mbed.h" #include "SAA1064.h" -/** Create an SAA1064 object connected to the specified I2C object and using the specified deviceAddress - * - * @param I2C &i2c the I2C port to connect to - * @param char deviceAddress the address of the SAA1064 -*/ -SAA1064::SAA1064(I2C *i2c, char deviceAddress) : _i2c(i2c) { + +/** 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::SAA1064(I2C *i2c, uint8_t deviceAddress) : _i2c(i2c) { _slaveAddress = deviceAddress; _init(); }; -char SAA1064::read() { - char tmp = 0; - - return tmp; -}; - -void SAA1064::write(char byte) { -}; - - - -void SAA1064::setIntensity(unsigned char intensity) { - char data[6]; +/** Set segment brightness + * + * @param intensity intensity value, valid Range between 0-7, 0 = 0 mA/segment, 1 = 3 mA/segment etc + */ +void SAA1064::setIntensity(uint8_t intensity) { + uint8_t data[6]; intensity = (intensity & 0x07) << 4; // Valid Range between 0-7 // 0 = 0 mA/segment, 1 = 3 mA/segment etc @@ -39,14 +33,20 @@ data[1] = SAA1064_CTRL_DEF | intensity; // Init Control Reg // write data to the display - _i2c->write(_slaveAddress, data, 2); + _i2c->write(_slaveAddress, (char*) data, 2); }; - -void SAA1064::write(unsigned char digit1, unsigned char digit2, unsigned char digit3, unsigned char digit4) { - char data[6]; +/** 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 SAA1064::write(uint8_t digit1, uint8_t digit2, uint8_t digit3, uint8_t digit4) { + uint8_t data[6]; data[0] = SAA1064_DIG1; // Select Digit1 Reg data[1] = digit1; // Digit 1 @@ -55,13 +55,20 @@ data[4] = digit4; // Digit 4 // write data to the display - _i2c->write(_slaveAddress, data, 5); + _i2c->write(_slaveAddress, (char*) data, 5); }; -void SAA1064::writeInt(int value, unsigned char dp_digit, bool leading) { - unsigned char digit_value; - char data[6]; + +/** 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 SAA1064::writeInt(int value, uint8_t dp_digit, bool leading) { + uint8_t digit_value; + uint8_t data[6]; data[0] = SAA1064_DIG1; // Select Digit1 Reg @@ -139,13 +146,72 @@ } // write data to the display - _i2c->write(_slaveAddress, data, 5); + _i2c->write(_slaveAddress, (char*) data, 5); }; +/** snake: show a short animation + * + * @param count number of times animation is repeated, valid range 0..15 + * + */ +void SAA1064::snake(uint8_t count) { + uint8_t i; + const float step = 0.1; +// const float loop = 0.1; + + count = count & 0x0F; // Limit max count + + for (i=0; i<count; i++) { + write(0x00,0x00,0x00,0x01); wait(step); + write(0x00,0x00,0x01,0x01); wait(step); + write(0x00,0x01,0x01,0x01); wait(step); + write(0x01,0x01,0x01,0x00); wait(step); + write(0x21,0x01,0x00,0x00); wait(step); + write(0x31,0x00,0x00,0x00); wait(step); + write(0x38,0x00,0x00,0x00); wait(step); + write(0x18,0x08,0x00,0x00); wait(step); + write(0x08,0x08,0x08,0x00); wait(step); + write(0x00,0x08,0x08,0x08); wait(step); + write(0x00,0x00,0x08,0x0C); wait(step); + write(0x00,0x00,0x00,0x0E); wait(step); + write(0x00,0x00,0x00,0x06); wait(step); + write(0x00,0x00,0x00,0x02); wait(step); + write(0x00,0x00,0x00,0x00); wait(step); + +// wait(loop) + } +} + + +/** splash: show a short animation + * + * @param count number of times animation is repeated, valid range 0..15 + * + */ +void SAA1064::splash (uint8_t count){ + uint8_t i; + const float step = 0.3; +// const float loop = 0.1; + + count = count & 0x0F; // Limit max count + + for (i=0; i<count; i++) { + write(0x00,0x40,0x40,0x00); wait(step); + write(0x39,0x09,0x09,0x0F); wait(step); + +// wait(loop) + } + write(0x00,0x00,0x00,0x00); +} + + +/** Initialise LED driver + * + */ void SAA1064::_init() { - char data[6]; + uint8_t data[6]; data[0] = SAA1064_CTRL; // Select Control Reg data[1] = SAA1064_CTRL_DEF | SAA1064_INT3; // Init Control Reg @@ -160,6 +226,6 @@ // data[5] = SAA1064_ALL; // Digit 4: All Segments On // write data to the display - _i2c->write(_slaveAddress, data, 6); + _i2c->write(_slaveAddress, (char*) data, 6); };