High Score - JuliaElizabethLittle/peeMarksmanship GitHub Wiki

Once we'd got the code to calculate the score we simply had to tweak it a bit so as to have it calculating the high score. It required a small "memory system" for we wanted the arduino to remember the highest score and contrast it with all new scores so it would know weather to update it or not.

So we started by creating the following variables


int score = 0;
int highscore = 0;

We already had score but we included it for it is useful to explain this step. So at the beginning high score is set to be 0. As the loop starts the variable score will be updated in function of what values the sensors receive. Once the score has been calculated and we pushbutton (pull the chain) we have the following code:


if (chain == LOW) {
      counter = 0;
      lcd.clear();
      lcd.print(score);
      
      if(highscore<score){
        
        highscore = score;

The second if only happens if the chain is being pulled and it says that is the value of high score is smaller that 0 it must update it's value to be equal to the score. The first time this happens of course it will be updated, for any value will be higher than 0. After that Arduino will remember this value, and until a newer, higher score is processed it won't be updated. Saving this way the highest value all the time.

The next step was trying out the LCD