How to capture last tries in reflex game

I made a simple reflex game using Arduino where I have RGB diod and buttons with LCD display
something like on this website :

You have to press the button as soon as the diod turns on and it will write you your delay on the display after pressing the button
I was wondering how to make code if I would like to capture my last 10 tries and write them down on the display after pressing specific button.

Welcome to the forum

Put the delay times in an arrays as they happen and read them out when the output button is pressed

In order to store only the last 10 tries then you need to use the array as a circular buffer. Do some reading on that subject to see what is involved. It does not involve moving the values stored in the array. There is a much better way

1 Like

What do these last ten tries look like now? (copy/paste them into your post)

Here is how to sequentially read a buffer by using a counter. You can save your times into the buffer, then later read the times back.

// int buf[10]; // Create an empty buffer the right size

// This is an example of a full buffer just for testing this sketch
int buf[] = {78, 101, 118, 101, 114, 32, 103, 111, 110, 110, 97, 32, 103, 105, 118, 101, 32, 121, 111, 117, 32, 117, 112, 33};

int bufLoc = 0; // Declare and initialize a buffer location counter
int bufSiz = sizeof(buf) / sizeof(buf[0]); // Calculate buffer size

void setup() {
  Serial.begin(300); // start the serial connection - VERIFY BAUD RATE MATCH
}

void loop() {
  Serial.print(bufLoc); // show the contents of the buffer at the location counter
  Serial.print(":"); // a delimiter to separate location from contents
  Serial.write(buf[bufLoc]); // show contents of buffer from the location
  Serial.println(); // next line, please
  bufLoc++; // increase buffer location counter
  if (bufLoc > bufSiz - 1) { // if counter is at the end of buffer...
    bufLoc = 0; // ... reset counter
    Serial.println("END OF BUFFER");
  }
}

That code has some issues, but nothing to keep you from plopping the successive values into an array.

Post the code that is something like something else. Your code.

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.