Forked LEDMatrix and added horizontal scrolling
Fork of LEDMatrix by
Diff: LEDMatrix.cpp
- Revision:
- 4:40d4afefcd74
- Parent:
- 3:1e06e89bc0c9
- Child:
- 5:334fc002e200
--- a/LEDMatrix.cpp Thu Jan 14 16:52:04 2016 +0000 +++ b/LEDMatrix.cpp Fri Jan 15 09:50:10 2016 +0000 @@ -59,12 +59,14 @@ _isBusy = false; _charSeparation = 1; _flashCounter = 0; - _flashRate = 8; + _flashRate = 50; _flashState = false; + _scrollCounter = 0; + _scrollRate = 7; } void LEDMatrix::begin(uint8_t *_pDisplayBuf, uint16_t width, uint16_t height, uint16_t dispBufWidth, - uint16_t numLines, int charSeparation, int flashRate) + uint16_t numLines, int charSeparation, int flashRate, int scrollRate) { ASSERT(0 == (width % LED_MATRIX_LEDS_HORIZONTALLY)); ASSERT(0 == (scroll_width % LED_MATRIX_LEDS_HORIZONTALLY)); @@ -76,7 +78,10 @@ this->dispBufWidth = dispBufWidth; this->numLines = numLines; this->_charSeparation = charSeparation; - this->_flashRate = flashRate; + if (flashRate > 0) + this->_flashRate = flashRate; + if (scrollRate > 0) + this->_scrollRate = scrollRate; if (numLines > LED_MATRIX_MAX_LINES) this->numLines = LED_MATRIX_MAX_LINES; for (int i = 0; i < LED_MATRIX_LEDS_VERTICALLY; i++) @@ -323,6 +328,16 @@ *ptr++ = 0x00; } +void LEDMatrix::setScrollRate(int rate) +{ + _scrollRate = rate; +} + +void LEDMatrix::setFlashRate(int rate) +{ + _flashRate = rate; +} + void LEDMatrix::setupScroll(int lineIdx, int scrollWidth, int scrollInc) { // Interpret param @@ -370,13 +385,17 @@ void LEDMatrix::serviceEffects() { - // Scroll / flash logic - int rowsInLine = (height / numLines); - for (int i = 0; i < numLines; i++) + // Scroll logic + _scrollCounter++; + if (_scrollCounter >= _scrollRate) { - for (int j = 0; j < rowsInLine; j++) - _hScrollPos[i*rowsInLine+j] += _lineScrollInc[i]; - _lineInvert[i] = _lineAlert[i] ? _flashState : false; + _scrollCounter = 0; + int rowsInLine = (height / numLines); + for (int i = 0; i < numLines; i++) + { + for (int j = 0; j < rowsInLine; j++) + _hScrollPos[i*rowsInLine+j] += _lineScrollInc[i]; + } } // Update flash state @@ -385,6 +404,10 @@ { _flashCounter = 0; _flashState = !_flashState; + for (int i = 0; i < numLines; i++) + { + _lineInvert[i] = _lineAlert[i] ? _flashState : false; + } } }