{
millisecondsPerLED -= deltaMillisecondsPerLED;
if (deltaMillisecondsPerLED > 5) //Because of this, it takes a little more time to reach to an insane speed. Adjust or remove this if rounds become too long.
{
deltaMillisecondsPerLED -= 5;
}
}
void MoveBallToNextPosition() //Moves the ball one spot.
{
previousPosition = currentPosition;
digitalWrite(previousPosition, 0);
currentPosition = currentPosition + deltaPosition;
digitalWrite(currentPosition, 1);
isInputAllowed = true;
}
void DetermineNextPosition()
{
if (willTheBallGoTowardsPlayerTwo)
{
deltaPosition = -1;
}
else
{
deltaPosition = 1;
}
}
void CheckGoalConditions()
{
if (currentPosition == goalPlayerTwo)
{
ScoreForPlayer(1);
}
else if (currentPosition == goalPlayerOne)
{
ScoreForPlayer(2);
}
}
void ScoreForPlayer(int playerWhoScored)
{
isInputAllowed = false;
FlashAllLEDs(1, 0);
if (playerWhoScored == 1)
{
scoreOfPlayerOne++;
Reset(1);
}
else if (playerWhoScored == 2)
{
scoreOfPlayerTwo++;
Reset(2);
}
}
void CheckEndGame()
{
if (scoreOfPlayerOne == 9)
{
delay(2000);
digitalWrite(display1,LOW);
digitalWrite(display2,LOW);
digitalWrite(display3,LOW);
digitalWrite(display4,LOW);
digitalWrite(display5,HIGH);
digitalWrite(display6,LOW);
digitalWrite(display7,LOW);
digitalWrite(display1,HIGH);
digitalWrite(display2,HIGH);
digitalWrite(display3,LOW);
digitalWrite(display4,LOW);
digitalWrite(display5,LOW);
digitalWrite(display6,LOW);
digitalWrite(display7,LOW);
EndGameCeremonyFor(1);
}
if (scoreOfPlayerTwo == 9)
{
delay(2000);
digitalWrite(A,LOW);
digitalWrite(B,LOW);
digitalWrite(C,LOW);
digitalWrite(D,LOW);
digitalWrite(E,HIGH);
digitalWrite(F,LOW);
digitalWrite(G,LOW);
digitalWrite(A,HIGH);
digitalWrite(B,HIGH);
digitalWrite(C,LOW);
digitalWrite(D,LOW);
digitalWrite(E,LOW);
digitalWrite(F,LOW);
digitalWrite(G,LOW);
63