Skip to content

Commit 811ada6

Browse files
small efficiency tweaks
1 parent 7ccb713 commit 811ada6

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

talkToMax-chainableled/talkToMax-chainableled.ino

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ const byte kD5Pin = 5;
5555
const byte kD6Pin = 6;
5656
const byte kD7Pin = 7;
5757

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

6161
// Setup function
6262
void setup()
@@ -122,9 +122,11 @@ void MapSensorToActuator()
122122
void SerialWriteSensorValues()
123123
{
124124
// Let's send max 25 times per second
125-
if (millis() > (lastSensorValuesWrittenMark + sensorSampleInterval))
125+
unsigned long timeNow = millis();
126+
if (timeNow > (lastSensorValuesWrittenMark + sensorSampleInterval))
126127
{
127128
// Send all values on one line separated by spaces to Max
129+
128130
Serial.print("s ");
129131
Serial.print(A0_value);
130132
Serial.print(" ");
@@ -134,7 +136,7 @@ void SerialWriteSensorValues()
134136
Serial.print(" ");
135137
Serial.print(A3_value);
136138
Serial.print("\n");
137-
lastSensorValuesWrittenMark = millis();
139+
lastSensorValuesWrittenMark = timeNow;
138140
}
139141
}
140142

@@ -348,4 +350,4 @@ void DoLightShow()
348350
leds.setColorRGB(i, 0, 0, 0);
349351
delay(100);
350352
}
351-
353+

0 commit comments

Comments
 (0)