Skip to content

Commit 4f1a83d

Browse files
added support for gray-scale images
Added support for gray scale images on mono-color LED matrices.
1 parent 87bd7ac commit 4f1a83d

18 files changed

+505
-344
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77
## [Unreleased]
88

99
### Changed
10-
- Refactored the image classes to have a common, templated base class. This consolidates similar logic to a single location.
10+
- Refactored the image classes to have a common, templated base class. This consolidates similar logic to a single location. This caused the existing Glyph object to have it's API slightly changed.
11+
- Improved interrupt handling on 8-bit AVR microcontrollers
1112

1213
### Added
1314
- Support for the Arduino Zero and Due boards (and related)
1415
- Support for older ATmega8535, ATmega16 and ATmega32 microcontrollers
1516
- Support for ATmega1284 and ATmega1284P microcontrollers
1617
- A method to LEDImage for drawing circles
1718
- A Red-Blue-Green bit layout mode for the RGB matrix object
18-
- An option to shift out an "all off" signal for a short period of time in between row updates to the shift registers. This helps mitigate LEF ghosting when the time to turn off for the row power switch is appreciable and cannot be mitigated in hardware. For example, when using 2981 source drivers for the row power switching.
19+
- An option to shift out an "all off" signal for a short period of time in between row updates to the shift registers. This helps mitigate LED ghosting when the time to turn off for the row power switch is appreciable and cannot be mitigated in hardware. For example, when using 2981 source drivers for the row power switching, which requires 2 microseconds to turn off.
20+
- Added support for a "gray scale" LED matrix. This is a mono-color LED matrix where PWM is used to effect varying intensity in each LED.
1921

2022

2123
## [1.0.1] - 2017-12-24

keywords.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ Frame KEYWORD1
1111
Glyph KEYWORD1
1212
GlyphBase KEYWORD1
1313
GlyphSequenceAnimation KEYWORD1
14+
GrayScaleColorType KEYWORD1
15+
GrayScaleImage KEYWORD1
16+
GrayScaleLEDMatrix KEYWORD1
1417
ImageSequenceAnimation KEYWORD1
1518
LEDMatrix KEYWORD1
1619
LEDMatrixBits KEYWORD1
@@ -69,3 +72,10 @@ YELLOW_COLOR LITERAL1
6972
INDIVIDUAL_LEDS LITERAL1
7073
RGB_GROUPS LITERAL1
7174
RBG_GROUPS LITERAL1
75+
76+
GRAYSCALE_BLACK LITERAL1
77+
GRAYSCALE_DARK_GRAY LITERAL1
78+
GRAYSCALE_LIGHT_GRAY LITERAL1
79+
GRAYSCALE_MEDIUM_GRAY LITERAL1
80+
GRAYSCALE_TRANSPARENT LITERAL1
81+
GRAYSCALE_WHITE LITERAL1

library.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name=Shift Register LED Matrix Lib
2-
version=1.0.1
2+
version=1.1.0
33
author=Michael Kamprath <michael@kamprath.net>
44
maintainer=Michael Kamprath <michael@kamprath.net>
55
sentence=A driver for LED matrices that use shift registers to control rows and columns.
66
paragraph=Provides a high level API for managing and drawing to the LED matrix. Can drive either a single color or RGB LED matrices. Color shading is enabled using PWM-style updates to the matrix shift registers. Uses a clock interrupt. Designed to be used with 74HC595 and/or DM13A type shift registers, or similar. See website for hardware designs supported.
77
category=Display
88
url=http://www.kamprath.net/led-matrix/
99
architectures=*
10-
includes=LEDMatrix.h,RGBLEDMatrix.h,RGBImage.h,Glyph.h,RGBAnimation.h,RGBAnimationSequence.h,TimerAction.h
10+
includes=LEDMatrix.h,GrayScaleLEDMatrix.h,RGBLEDMatrix.h,GrayScaleImage.h,RGBImage.h,Glyph.h,RGBAnimation.h,RGBAnimationSequence.h,TimerAction.h

src/BaseLEDMatrix.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@
1919
#include "BaseLEDMatrix.h"
2020
#include "SRLEDMatrixUtils.h"
2121

22-
#ifndef ICACHE_RAM_ATTR
23-
#define ICACHE_RAM_ATTR
24-
#endif
25-
2622
const unsigned long UPDATE_INTERVAL = 2000;
2723

2824
static BaseLEDMatrix* gSingleton = NULL;
@@ -448,12 +444,12 @@ void TC3_Handler() // Interrupt Service Routine (IS
448444
// scan timing.
449445
//
450446

451-
#define BASE_SCAN_TIMER_INTERVALS 12
447+
#define BASE_SCAN_TIMER_INTERVALS 24
452448

453449
void BaseLEDMatrix::startScanning(void) {
454450
this->setup();
455451

456-
_interFrameOffTimeInterval = max(257 - (BASE_SCAN_TIMER_INTERVALS/5)*_interFrameOffTimeMicros, 0);
452+
_interFrameOffTimeInterval = max(255 - _interFrameOffTimeMicros, 0);
457453

458454
noInterrupts(); // disable all interrupts
459455

@@ -468,13 +464,13 @@ void BaseLEDMatrix::startScanning(void) {
468464
// overflow only mode
469465
TIMSK2 &= ~(1<<OCIE2A);
470466

471-
// configure to fire about every 5 micro-second
472-
TCCR2B |= (1<<CS22) ;
473-
TCCR2B &= ~(1<<CS20);
474-
TCCR2B &= ~(1<<CS21);
467+
// configure prescaler to /32
468+
TCCR2B |= (1<<CS20);
469+
TCCR2B |= (1<<CS21);
470+
TCCR2B &= ~(1<<CS22) ;
475471

476472
// load counter start point and enable the timer
477-
TCNT2 = this->nextRowScanTimerInterval();
473+
TCNT2 = 0; // max interval for first timer fire
478474
TIMSK2 |= (1<<TOIE2);
479475

480476
interrupts(); // enable all interrupts
@@ -485,6 +481,7 @@ void BaseLEDMatrix::stopScanning(void) {
485481
}
486482

487483
unsigned int BaseLEDMatrix::nextRowScanTimerInterval(void) const {
484+
// this yields multiple of 50 microseconds on a 16 MHz chip
488485
return max(257 - this->baseIntervalMultiplier( _scanPass )*BASE_SCAN_TIMER_INTERVALS, 0 );
489486
}
490487

src/BaseLEDMatrix.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525

2626
#define LED_MATRIX_MAX_SCAN_PASS_COUNT 1
2727

28+
#ifndef ICACHE_RAM_ATTR
29+
#define ICACHE_RAM_ATTR
30+
#endif
31+
2832
class BaseLEDMatrix : public TimerAction {
2933

3034
private:
@@ -84,7 +88,9 @@ class BaseLEDMatrix : public TimerAction {
8488
* be waited until the next row update gets shifted out. Usually a value
8589
* less than 3 microseconds is sufficient for most slow row power
8690
* switching.
87-
* @param slavePin which ard pin is used for the latch signal.
91+
* @param slavePin which pin is used for the latch signal.
92+
* @param maxSPISpeed The requested max SPI speed. The board typically picks the
93+
* smaller of this and it's own max.
8894
*/
8995
BaseLEDMatrix(
9096
unsigned int rows,

0 commit comments

Comments
 (0)