Hello all, I have been having some issues with some code of mine.
I have a function which requires the millis() function in order to calculate the elapsed time since a beginning time in milliseconds, but i have been having some issues. In the code, I try to calculate the elapsed time by subtracting the start time from millis(), but the function outputs this (the red line is the vlaues outputted):
with the inputs:
transitionIn(20, 0, 2500, 1000, star)
I have tried everything and yet I still cannot get this function to work! can someone please help me?
Here is the broken function:
point movePoint (int16_t x, int16_t y, uint32_t be, uint16_t len, point p1, point p2) {
p1.offset(x, y);
p2.offset(x, y);
if (millis() < be) {
return p1;
} else if (millis() > be + len) {
return p2;
}
uint32_t elp = millis() - be; // problematic line
float per = float(elp) / float(len);
//float adj = (sin(PI * (per - 0.5)) / 2.0) + 0.5; uncomment to calculate curve
float adj = lerp(
curve[clip(per * 20, 19)],
curve[clip(per * 20 + 1, 19)],
float(per * 20.0) - float(floor(per * 20.0))
);
//Serial.println(String(per * 100) + '\t' + String(adj * 100));
Serial.println(String(len) + '\t' + String(elp));
//Serial.println(String(adj * 100));
return lerp(p1, p2, adj);
}