Skip to content

Commit

Permalink
small efficiency tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
dietervandoren authored Dec 5, 2017
1 parent 7ccb713 commit 811ada6
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions talkToMax-chainableled/talkToMax-chainableled.ino
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ const byte kD5Pin = 5;
const byte kD6Pin = 6;
const byte kD7Pin = 7;

long lastSensorValuesWrittenMark = 0; // Remember the last time data was send
int sensorSampleInterval = 40; // Send sensor date every N milliseconds
unsigned long lastSensorValuesWrittenMark = 0; // Remember the last time data was send
unsigned long sensorSampleInterval = 40; // Send sensor date every N milliseconds

// Setup function
void setup()
Expand Down Expand Up @@ -122,9 +122,11 @@ void MapSensorToActuator()
void SerialWriteSensorValues()
{
// Let's send max 25 times per second
if (millis() > (lastSensorValuesWrittenMark + sensorSampleInterval))
unsigned long timeNow = millis();
if (timeNow > (lastSensorValuesWrittenMark + sensorSampleInterval))
{
// Send all values on one line separated by spaces to Max

Serial.print("s ");
Serial.print(A0_value);
Serial.print(" ");
Expand All @@ -134,7 +136,7 @@ void SerialWriteSensorValues()
Serial.print(" ");
Serial.print(A3_value);
Serial.print("\n");
lastSensorValuesWrittenMark = millis();
lastSensorValuesWrittenMark = timeNow;
}
}

Expand Down Expand Up @@ -348,4 +350,4 @@ void DoLightShow()
leds.setColorRGB(i, 0, 0, 0);
delay(100);
}


0 comments on commit 811ada6

Please sign in to comment.