Hi Toastycoast,
it's a feature hahah ... we want the ball to keep bouncing.
To limit the bouncing, change the code where it says "while(true)" (which is an indefinite loop, keeps going and going) to something like this (I added "//" to disable the line and at the end to disable the closing bracket "}" - identified the 2 lines by adding "// <--- change here!").
void loop() {
byte colors[3][3] = { {0xff, 0,0},
{0xff, 0xff, 0xff},
{0 , 0 , 0xff} };
BouncingColoredBalls(3, colors);
}
void BouncingColoredBalls(int BallCount, byte colors[][3]) {
float Gravity = -9.81;
int StartHeight = 1;
float Height[BallCount];
float ImpactVelocityStart = sqrt( -2 * Gravity * StartHeight );
float ImpactVelocity[BallCount];
float TimeSinceLastBounce[BallCount];
int Position[BallCount];
long ClockTimeSinceLastBounce[BallCount];
float Dampening[BallCount];
for (int i = 0 ; i < BallCount ; i++) {
ClockTimeSinceLastBounce = millis();
Height = StartHeight;
Position = 0;
ImpactVelocity = ImpactVelocityStart;
TimeSinceLastBounce = 0;
Dampening = 0.90 - float(i)/pow(BallCount,2);
}
// while (true) { // <--- change here!
for (int i = 0 ; i < BallCount ; i++) {
TimeSinceLastBounce = millis() - ClockTimeSinceLastBounce;
Height = 0.5 * Gravity * pow( TimeSinceLastBounce/1000 , 2.0 ) + ImpactVelocity * TimeSinceLastBounce/1000;
if ( Height < 0 ) {
Height = 0;
ImpactVelocity = Dampening * ImpactVelocity;
ClockTimeSinceLastBounce = millis();
if ( ImpactVelocity < 0.01 ) {
ImpactVelocity = ImpactVelocityStart;
}
}
Position = round( Height * (NUM_LEDS - 1) / StartHeight);
}
for (int i = 0 ; i < BallCount ; i++) {
setPixel(Position,colors[0],colors[1],colors[2]);
}
showStrip();
setAll(0,0,0);
// } // <--- change here!
}
Hope this helps ...