Skip to content

Commit

Permalink
Updating Chaser.ino and Flasher.ino examples to properly wait for the…
Browse files Browse the repository at this point in the history
… serial monitor at program start and changing the baud rate to 115200. Also updating the Flasher.ino print interval to 1000ms and slightly optimizing its wave calculation. Last, updating the library version to 2.3.2.
  • Loading branch information
ssilverman committed Nov 2, 2018
1 parent 7460208 commit 05180d6
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

This document details the changes between each release.

## [2.3.2]

### Changed
* Chaser.ino and Flasher.ino examples now properly wait for the serial monitor
at program start. The baud was also changed to 115200.
* Changed print interval in Flasher.ino to 1000ms.
* Slightly optimized the Flasher.ino wave calculation.

## [2.3.1]

### Added
Expand Down
5 changes: 3 additions & 2 deletions examples/Chaser/Chaser.ino
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ teensydmx::Sender dmxTx{Serial1};
int channel;

void setup() {
Serial.begin(9600);
delay(2000); // Instead of while (!Serial), doesn't seem to work on Teensy
Serial.begin(115200);
while (!Serial && millis() < 4000) { // Wait for the serial monitor to come up
}
Serial.println("Starting.");

dmxTx.begin();
Expand Down
23 changes: 13 additions & 10 deletions examples/Flasher/Flasher.ino
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ constexpr unsigned long kDMXTimeout = 1000;
constexpr uint8_t kLEDPin = 13;

// Interval between printing received values.
constexpr unsigned long kPrintInterval = 500;
constexpr unsigned long kPrintInterval = 1000;

namespace teensydmx = ::qindesign::teensydmx;

Expand All @@ -31,8 +31,9 @@ elapsedMillis lastFrameTime;
uint8_t lastValue;

void setup() {
Serial.begin(9600);
delay(2000); // Instead of while (!Serial), doesn't seem to work on Teensy
Serial.begin(115200);
while (!Serial && millis() < 4000) { // Wait for the serial monitor to come up
}
Serial.println("Starting.");

pinMode(kLEDPin, OUTPUT);
Expand All @@ -59,13 +60,15 @@ void loop() {
if (lastFrameTime < kDMXTimeout) {
// Use a wave equation to make the speed-ups and slow-downs smoother
// using the offset, phi
static int period = 1000;
static long phi = 0 * period;
int newPeriod = map(lastValue, 0, 255, 1000, 30); // T range is 1s to 30ms
long t = static_cast<long>(millis());
phi = (t*period - newPeriod*(t - phi))/period;
period = newPeriod;
int v = static_cast<int>(-(phi - t)%period);
static int32_t period = 1000;
static int64_t phi = 0 * period;
int32_t newPeriod = map(lastValue, 0, 255, 1000, 30); // T range is 1s to 30ms
int64_t t = millis();
if (newPeriod != period) {
phi = (t*(period - newPeriod) + newPeriod*phi)/period;
period = newPeriod;
}
int32_t v = -(phi - t)%period;

if (v < period/2) {
digitalWrite(kLEDPin, HIGH);
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"type": "git",
"url": "https://github.com/ssilverman/TeensyDMX"
},
"version": "2.3.1",
"version": "2.3.2",
"license": "BSD-3-Clause",
"homepage": "https://github.com/ssilverman/TeensyDMX",
"frameworks": "arduino",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=TeensyDMX
version=2.3.1
version=2.3.2
author=Shawn Silverman <[email protected]>
maintainer=Shawn Silverman <[email protected]>
sentence=A DMX library for the Teensy.
Expand Down

0 comments on commit 05180d6

Please sign in to comment.