Sounds like fun!
-
the arduino can generate random sequences of targets but you could also have build in practice sequences. As you only use the numbers 1..5 you can store one target in one byte (in fact you can compress and store 3 in one byte)
-
I expect it can even register how long it took to shoot a target.
-
If someone is shooting good and fast it can decrease the time from 5 seconds to 4 to 3 to ....
-
it can store high score in EEPROM
Could not resist to dump some code to get you started, still leaves a lot todo
void setup()
{
Serial.begin(9600);
Serial.println("Shooting game 0.01");
}
void loop()
{
displayMenu();
char choice = getChoice();
switch(choice)
{
case 'h' : displayHighScore(); break;
case 'n' : playGame(true, 10); break;
case 'e' : playGame(false, 25); break;
}
}
void displayMenu()
{
Serial.println("h : highscore");
Serial.println("n : newgame");
Serial.println("e : exercise");
Serial.println("Enter your choice>");
}
char getChoice()
{
while(Serial.available() == 0);
return (char) Serial.read();
}
void playGame(bool forReal, int targets)
{
unsigned long timeused = millis();
int hits = 0;
for (int i =0; i< targets; i++)
{
setRandomTarget();
unsigned long start = millis(); // wait max 5 seconds or target shot
while (millis() - start < 5000)
{
if (targetHit() == true)
{
hits++;
break;
}
}
}
timeused = millis() - timeused;
Serial.print("Score: ");
Serial.print(hits );
Serial.print(" in ");
Serial.print(timeused/1000.0, 2);
Serial.println("Seconds ");
if (forReal)
{
HighScore(timeused, hits);
}
}
void setRandomTarget()
{
Serial.println("not yet implemented");
}
bool targetHit()
{
Serial.println("not yet implemented");
}
void displayHighScore()
{
Serial.println("not yet implemented => 0");
}
void HighScore(unsigned long time, int hits)
{
Serial.println("not yet implemented");
}
4 ) get started with an UNO