Need help saving user input to read back at a later time (array?)

So basically i have 3 buttons and i want to hit them an arbitrary amount of times (no more than 20-30) and then read back what i've pressed. Each button will represent a block of code. After pressing a fourth button, i want it to start running through the sequence of the pressed buttons.

For instance if i press ^ ^ ^ > ^ < ^ it will then sequentially execute the code for what those buttons represent.

Ive tried using an array but i really dont understand arrays. I was then going to use the EEPROM.write, and EEPROM.read but i may exceed the approximate 100,000 read/write life of the onboard eeprom by the time its all said and done.

Does anyone have any advice on how to do this? Hopefully i was clear enough on my description.

I just want to store and read out sequentially.

thanks

Thanks

Hopefully i was clear enough on my description.

Hope is a bit of a bugger.

ve tried using an array but i really dont understand arrays.

Then you have some learning to do. There is no way to do this without understanding arrays.

Declare a byte array big enough to hold the total number of button presses expected and an index variable to point at the next array entry to be used.

byte buttonPresses[40];
byte arrayIndex = 0;

Each time a button is pressed save the button number to the next array entry and increment the index variable and put a marker in the array to indicate where the end of the sequence is.

if (digitalRead(button1) == LOW)
{
  buttonPresses[arrayIndex] = 1;
  arrayindex++;
  buttonPresses[arrayIndex] = 99;
}

Do the same for the other two buttons, storing 2 or 3 as appropriate.

When the fourth button is pressed you can replay the sequence of stored numbers

arrayIndex = 0;
while (buttonPresses[arrayIndex] != 99)
{
  Serial.println(buttonPresses[arrayIndex]);
  arrayIndex++
}

There is still work for you to do to check the stored numbers as they are read from the array and to do whatever you want depending on the number but I suggest that you start by simply printing the numbers as above.

Nicely answered Helibob, deserves Karma :wink:

UKHeliBob:
and put a marker in the array to indicate where the end of the sequence is.

You shouldn't need to put a marker in the array to indicate the end if you're keeping track of the current index as you suggest.

Simply navigate thru the array from zero to "index minus one" and Bob's your uncle.

But I agree great answer.

Regards,

Brad
KF7FER

Agreed. The end of sequence marker is not necessary, but I quite like the idea as it is a very understandable technique, and the OP will encounter C style strings where a similar marker is absolutely necessary