Skip to content

Commit f3e4e32

Browse files
Add Support for Teensy 4.x (#14)
* addressed various compiler warnings * updated environment for platformio development * added support for teensy 4.x
1 parent 84fc5b5 commit f3e4e32

File tree

14 files changed

+188
-65
lines changed

14 files changed

+188
-65
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@
3333
artwork/
3434
test/
3535

36+
# Visual Code + PlatformIO
37+
.pio
38+
.vscode
39+
.travis.yml

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Added
9+
- Added a `platformio.ini` file to aid in the development of this library using hte Platform IO environment. This is only useful for developing this library itself, and not at all used for using this library in your projects.
10+
- Added support for Teensy 4.x boards
811

912
## [2.0.1]
1013
### Added

examples/10x10-matrix/color_gradient-10x10/color_gradient-10x10.ino

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,14 @@ RGBLEDMatrix leds(10,10);
88
void setup() {
99
leds.setup();
1010
leds.startDrawing();
11-
for (int y = 0; y < leds.rows(); y++ ) {
12-
for (int x = 0; x < leds.columns(); x++ ) {
11+
for (unsigned int y = 0; y < leds.rows(); y++ ) {
12+
for (unsigned int x = 0; x < leds.columns(); x++ ) {
1313
float dx = leds.columns() - x - 1;
1414
float dy = leds.rows()-y - 1;
15-
float dmy = leds.rows()/2.0-y;
1615

1716
float d_tl = max(1.0-sqrt(x*x + y*y)/MAX_DISTANCE, 0);
18-
float d_tr = max(1.0-sqrt(dx*dx + y*y)/MAX_DISTANCE, 0);
1917
float d_bl = max(1.0-sqrt(x*x + (leds.rows()-y)*(leds.rows()))/MAX_DISTANCE, 0);
2018
float d_br = max(1.0-sqrt(dx*dx + dy*dy)/MAX_DISTANCE, 0);
21-
float d_rm = max(1.0-sqrt(dx*dx + dmy*dmy)/(MAX_DISTANCE*3.0/4.0), 0);
2219

2320
RGBColorType c = RGBColor::fromRGB( d_tl*255, d_br*194, d_bl*255);
2421
leds.writePixel(x, y, c);

examples/10x10-matrix/dot-chaser-10x10/dot-chaser-10x10.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ private:
88
int _xVel;
99
int _yVel;
1010

11-
int _xStack[5] = {-1,-1,-1,-1,-1};
12-
int _yStack[5] = {-1,-1,-1,-1,-1};
11+
unsigned int _xStack[5] = {0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF};
12+
unsigned int _yStack[5] = {0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF};
1313

1414

1515
protected:
1616
virtual void action() {
1717
_screen->startDrawing();
18-
for (int x = 0; x < _screen->columns(); ++x) {
19-
for (int y = 0; y < _screen->rows(); ++y ) {
18+
for (unsigned int x = 0; x < _screen->columns(); ++x) {
19+
for (unsigned int y = 0; y < _screen->rows(); ++y ) {
2020
RGBColorType color = 0;
2121
if ( x == _xStack[4] && y == _yStack[4] ) {
2222
color = DARK_BLUE_COLOR;

examples/16x16-matrix/color_gradient-16x16-cprg/color_gradient-16x16-cprg.ino

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,15 @@ RGBLEDMatrix leds(16,16, RGBLEDMatrix::RGB_GROUPS_CPRG8, HIGH, LOW, 3);
88
void setup() {
99
leds.setup();
1010
leds.startDrawing();
11-
for (int y = 0; y < leds.rows(); y++ ) {
12-
for (int x = 0; x < leds.columns(); x++ ) {
11+
for (unsigned int y = 0; y < leds.rows(); y++ ) {
12+
for (unsigned int x = 0; x < leds.columns(); x++ ) {
1313
float dx = leds.columns() - x - 1;
1414
float dy = leds.rows()-y - 1;
15-
float dmy = leds.rows()/2.0-y;
1615

1716
float d_tl = max(1.0-sqrt(x*x + y*y)/MAX_DISTANCE, 0);
18-
float d_tr = max(1.0-sqrt(dx*dx + y*y)/MAX_DISTANCE, 0);
1917
float d_bl = max(1.0-sqrt(x*x + (leds.rows()-y)*(leds.rows()))/MAX_DISTANCE, 0);
2018
float d_br = max(1.0-sqrt(dx*dx + dy*dy)/MAX_DISTANCE, 0);
21-
float d_rm = max(1.0-sqrt(dx*dx + dmy*dmy)/(MAX_DISTANCE*3.0/4.0), 0);
22-
19+
2320
RGBColorType c = RGBColor::fromRGB( d_tl*255, d_br*194, d_bl*255);
2421
leds.writePixel(x, y, c);
2522
}

examples/16x16-matrix/conway-game-of-life-16x16-cprg/conway-game-of-life-16x16-cprg.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ void CellUniverse::setCellStatus(unsigned int row, unsigned int column, LifeStat
8383

8484
CellUniverse::LifeState CellUniverse::getCellStatus(int row, int column) const {
8585
// this causes the matrix to be a toroidal array
86-
unsigned int r = row < 0 ? row + _leds.rows() : ( row >= _leds.rows() ? row - _leds.rows() : row );
87-
unsigned int c = column < 0 ? column + _leds.columns() : ( column >= _leds.columns() ? column - _leds.columns() : column );
86+
unsigned int r = row < 0 ? row + _leds.rows() : ( row >= (int)_leds.rows() ? row - _leds.rows() : row );
87+
unsigned int c = column < 0 ? column + _leds.columns() : ( column >= (int)_leds.columns() ? column - _leds.columns() : column );
8888

8989
// double check just to be sure
9090
if (r >= _leds.rows() || c >= _leds.columns()) {

examples/16x16-matrix/dot-chaser-16x16-cprg/dot-chaser-16x16-cprg.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ private:
88
int _xVel;
99
int _yVel;
1010

11-
int _xStack[5] = {-1,-1,-1,-1,-1};
12-
int _yStack[5] = {-1,-1,-1,-1,-1};
11+
unsigned int _xStack[5] = {0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF};
12+
unsigned int _yStack[5] = {0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF};
1313

1414

1515
protected:
1616
virtual void action() {
1717
_screen->startDrawing();
18-
for (int x = 0; x < _screen->rows(); ++x) {
19-
for (int y = 0; y < _screen->columns(); ++y ) {
18+
for (unsigned int x = 0; x < _screen->rows(); ++x) {
19+
for (unsigned int y = 0; y < _screen->columns(); ++y ) {
2020
RGBColorType color = 0;
2121
if ( x == _xStack[4] && y == _yStack[4] ) {
2222
color = DARK_BLUE_COLOR;

examples/16x16-matrix/plasma-16x16-cprg/plasma-16x16-cprg.ino

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -88,42 +88,35 @@ void setup() {
8888
leds.startScanning();
8989
}
9090

91-
unsigned long loopCounter = 0;
9291
unsigned long timeCount = 0;
9392
bool timeIncrement = true;
9493

95-
#if (defined(__arm__)&& defined(TEENSYDUINO) || defined(ESP32))
96-
// slow things down for the Teensy
97-
const unsigned long loopMod = 10000;
98-
#else
99-
const unsigned long loopMod = 50;
100-
#endif
101-
10294
void loop() {
10395
leds.loop();
104-
loopCounter++;
10596

106-
if (loopCounter == loopMod) {
107-
if (timeIncrement) {
108-
timeCount++;
109-
110-
//
111-
// set a maximum to timeCount because floats only have
112-
// a max precision of 5 significant digits. Otherwise, when timeCount
113-
// gets too large, the animation will get choppy because calls to drawPlasma()
114-
// will not have a noticable change to timeCount/TIME_DILATION. for several
115-
// consecutive calls.
116-
//
117-
if (timeCount >= 1000*PI) {
118-
timeIncrement = false;
119-
}
120-
} else {
121-
timeCount--;
122-
if (timeCount == 0) {
123-
timeIncrement = true;
124-
}
97+
// update frame every 40 milleseconds. AVR chips are slow enough to not need this delay.
98+
#if !defined(ARDUINO_ARCH_AVR)
99+
delay(40);
100+
#endif
101+
102+
if (timeIncrement) {
103+
timeCount++;
104+
105+
//
106+
// set a maximum to timeCount because floats only have
107+
// a max precision of 5 significant digits. Otherwise, when timeCount
108+
// gets too large, the animation will get choppy because calls to drawPlasma()
109+
// will not have a noticable change to timeCount/TIME_DILATION. for several
110+
// consecutive calls.
111+
//
112+
if (timeCount >= 1000*PI) {
113+
timeIncrement = false;
114+
}
115+
} else {
116+
timeCount--;
117+
if (timeCount == 0) {
118+
timeIncrement = true;
125119
}
126-
drawPlasma(timeCount);
127-
loopCounter = 0;
128120
}
121+
drawPlasma(timeCount);
129122
}

examples/8x8-matrix/color_gradient-8x8/color_gradient-8x8.ino

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,14 @@ RGBLEDMatrix leds(8,8);
88
void setup() {
99
leds.setup();
1010
leds.startDrawing();
11-
for (int y = 0; y < leds.rows(); y++ ) {
12-
for (int x = 0; x < leds.columns(); x++ ) {
11+
for (unsigned int y = 0; y < leds.rows(); y++ ) {
12+
for (unsigned int x = 0; x < leds.columns(); x++ ) {
1313
float dx = leds.columns() - x - 1;
1414
float dy = leds.rows()-y - 1;
15-
float dmy = leds.rows()/2.0-y;
1615

1716
float d_tl = max(1.0-sqrt(x*x + y*y)/MAX_DISTANCE, 0);
18-
float d_tr = max(1.0-sqrt(dx*dx + y*y)/MAX_DISTANCE, 0);
1917
float d_bl = max(1.0-sqrt(x*x + (leds.rows()-y)*(leds.rows()))/MAX_DISTANCE, 0);
2018
float d_br = max(1.0-sqrt(dx*dx + dy*dy)/MAX_DISTANCE, 0);
21-
float d_rm = max(1.0-sqrt(dx*dx + dmy*dmy)/(MAX_DISTANCE*3.0/4.0), 0);
2219

2320
RGBColorType c = RGBColor::fromRGB( d_tl*255, d_br*194, d_bl*255);
2421
leds.writePixel(x, y, c);

examples/8x8-matrix/dot-chaser-8x8/dot-chaser-8x8.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ private:
88
int _xVel;
99
int _yVel;
1010

11-
int _xStack[5] = {-1,-1,-1,-1,-1};
12-
int _yStack[5] = {-1,-1,-1,-1,-1};
11+
unsigned int _xStack[5] = {0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF};
12+
unsigned int _yStack[5] = {0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF};
1313

1414

1515
protected:
1616
virtual void action() {
1717
_screen->startDrawing();
18-
for (int x = 0; x < _screen->rows(); ++x) {
19-
for (int y = 0; y < _screen->columns(); ++y ) {
18+
for (unsigned int x = 0; x < _screen->rows(); ++x) {
19+
for (unsigned int y = 0; y < _screen->columns(); ++y ) {
2020
RGBColorType color = 0;
2121
if ( x == _xStack[4] && y == _yStack[4] ) {
2222
color = DARK_BLUE_COLOR;

0 commit comments

Comments
 (0)