Skip to content

Commit

Permalink
added support for gray-scale images
Browse files Browse the repository at this point in the history
Added support for gray scale images on mono-color LED matrices.
  • Loading branch information
michaelkamprath committed Feb 6, 2018
1 parent 87bd7ac commit 4f1a83d
Show file tree
Hide file tree
Showing 18 changed files with 505 additions and 344 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]

### Changed
- Refactored the image classes to have a common, templated base class. This consolidates similar logic to a single location.
- 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.
- Improved interrupt handling on 8-bit AVR microcontrollers

### Added
- Support for the Arduino Zero and Due boards (and related)
- Support for older ATmega8535, ATmega16 and ATmega32 microcontrollers
- Support for ATmega1284 and ATmega1284P microcontrollers
- A method to LEDImage for drawing circles
- A Red-Blue-Green bit layout mode for the RGB matrix object
- 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.
- 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.
- 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.


## [1.0.1] - 2017-12-24
Expand Down
10 changes: 10 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Frame KEYWORD1
Glyph KEYWORD1
GlyphBase KEYWORD1
GlyphSequenceAnimation KEYWORD1
GrayScaleColorType KEYWORD1
GrayScaleImage KEYWORD1
GrayScaleLEDMatrix KEYWORD1
ImageSequenceAnimation KEYWORD1
LEDMatrix KEYWORD1
LEDMatrixBits KEYWORD1
Expand Down Expand Up @@ -69,3 +72,10 @@ YELLOW_COLOR LITERAL1
INDIVIDUAL_LEDS LITERAL1
RGB_GROUPS LITERAL1
RBG_GROUPS LITERAL1

GRAYSCALE_BLACK LITERAL1
GRAYSCALE_DARK_GRAY LITERAL1
GRAYSCALE_LIGHT_GRAY LITERAL1
GRAYSCALE_MEDIUM_GRAY LITERAL1
GRAYSCALE_TRANSPARENT LITERAL1
GRAYSCALE_WHITE LITERAL1
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name=Shift Register LED Matrix Lib
version=1.0.1
version=1.1.0
author=Michael Kamprath <michael@kamprath.net>
maintainer=Michael Kamprath <michael@kamprath.net>
sentence=A driver for LED matrices that use shift registers to control rows and columns.
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.
category=Display
url=http://www.kamprath.net/led-matrix/
architectures=*
includes=LEDMatrix.h,RGBLEDMatrix.h,RGBImage.h,Glyph.h,RGBAnimation.h,RGBAnimationSequence.h,TimerAction.h
includes=LEDMatrix.h,GrayScaleLEDMatrix.h,RGBLEDMatrix.h,GrayScaleImage.h,RGBImage.h,Glyph.h,RGBAnimation.h,RGBAnimationSequence.h,TimerAction.h
19 changes: 8 additions & 11 deletions src/BaseLEDMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
#include "BaseLEDMatrix.h"
#include "SRLEDMatrixUtils.h"

#ifndef ICACHE_RAM_ATTR
#define ICACHE_RAM_ATTR
#endif

const unsigned long UPDATE_INTERVAL = 2000;

static BaseLEDMatrix* gSingleton = NULL;
Expand Down Expand Up @@ -448,12 +444,12 @@ void TC3_Handler() // Interrupt Service Routine (IS
// scan timing.
//

#define BASE_SCAN_TIMER_INTERVALS 12
#define BASE_SCAN_TIMER_INTERVALS 24

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

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

noInterrupts(); // disable all interrupts

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

// configure to fire about every 5 micro-second
TCCR2B |= (1<<CS22) ;
TCCR2B &= ~(1<<CS20);
TCCR2B &= ~(1<<CS21);
// configure prescaler to /32
TCCR2B |= (1<<CS20);
TCCR2B |= (1<<CS21);
TCCR2B &= ~(1<<CS22) ;

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

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

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

Expand Down
8 changes: 7 additions & 1 deletion src/BaseLEDMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@

#define LED_MATRIX_MAX_SCAN_PASS_COUNT 1

#ifndef ICACHE_RAM_ATTR
#define ICACHE_RAM_ATTR
#endif

class BaseLEDMatrix : public TimerAction {

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

0 comments on commit 4f1a83d

Please sign in to comment.