Please help me explain the logic of converting this?

premobowei:
Here's my disaster of a code.

int ledArray[10];

int buttonArray[10];

ledArray[55] = 0;
buttonArray[100] = 0;

Disaster indeed.

Every day's a Groundhog Day.

Making it difficult for people that are trying to help you -- FOR FREE -- is not a winning strategy

Amen

The codes I posted were from the Tinkercad so the Ctrl T function doesn't work there.
But here it is. There are some parts of this code that i"m not using and this is still a rough draft. I haven't ignored anyone who actually wants to help but many seem to be focused on things that aren't really the issue right now. If someone asks you to teach them how to drive, they're not asking you to point out the chip in the paint on their fender.

int ledArray[10];
int buttonArray[10];
int loopCounter;
int ledCounter;
int inputCounter;
int game;
int waiting;
int pass;
int wait;
int timeUp;

//ALL THE BUTTONS & LEDS ARE GIVEN NAMES HERE SO THEY'RE EASIER TO REFERENCE
const int buttonRed = 6;
const int buttonYellow = 7;
const int buttonGreen = 9;
const int buttonBlue = 8;
const int r = 2;
const int y = 3;
const int b = 4;
const int g = 5;
const int x = 10;//LED ON PIN 10 IS THE WHITE LED USED FOR PROMPTS


///USED FOR PROCESSING AND COMPARING INPUTS
int randNumber;
int array_Cmp;

void youWin ()
{ digitalWrite(2, HIGH);
  delay(100);
  digitalWrite(2, LOW);
  delay(100);
  digitalWrite(3, HIGH);
  delay(100);
  digitalWrite(3, LOW);
  delay(100);
  digitalWrite(4, HIGH);
  delay(100);
  digitalWrite(4, LOW);
  delay(100);
  digitalWrite(5, HIGH);
  delay(100);
  digitalWrite(5, LOW);
  delay(100);
}

void ledPrompt()
//prompts player for inout during game after
//the LEDs have been picked randomly each round
{ digitalWrite(x, HIGH);
  delay(1000);
  digitalWrite(x, LOW);
  delay(50);
}

void gameHasStarted()
//LED prompt after first button
//is pushed to start the game
{
  digitalWrite(10, HIGH);
  delay(1000);
  digitalWrite(10, LOW);
  delay(100);
}

void fail() //LED sequence when the wrong input is entered
{ digitalWrite(2, HIGH);
  delay(1000);
  digitalWrite(3, HIGH);
  delay(1000);
  digitalWrite(4, HIGH);
  delay(1000);
  digitalWrite(5, HIGH);
  delay(1000);
  digitalWrite(2, LOW);
  delay(50);
  digitalWrite(3, LOW);
  delay(50);
  digitalWrite(4, LOW);
  delay(50);
  digitalWrite(5, LOW);
  delay(50);
}

void waitToStart() //cycles through LEDs while waiting to start the game
{ digitalWrite(2, HIGH);
  delay(250);
  digitalWrite(2, LOW);
  delay(250);
  digitalWrite(3, HIGH);
  delay(250);
  digitalWrite(3, LOW);
  delay(250);
  digitalWrite(4, HIGH);
  delay(250);
  digitalWrite(4, LOW);
  delay(250);
  digitalWrite(5, HIGH);
  delay(250);
  digitalWrite(5, LOW);
  delay(250);
}

int initiate()//FUNCTION WAITS FOR ANY OF 4 BUTTONS TO BE PUSHED TO START THE GAME
{ game = 0;
  waiting = 0;
  loopCounter = 1;
  randNumber = 0;
  ledCounter = 0;
  inputCounter = 0;
  pass = 2;
  ledArray[55] = 0;
  buttonArray[100] = 0;
  //FUNCTION INCLUDES ALL OF THE ASSUMPTIONS NEEDED TO EXECUTE THE 1ST ROUND PROPERLY
  do {
    if (digitalRead(buttonRed) == LOW)
    { game = 2;
      gameHasStarted();
    }
    if (digitalRead(buttonGreen) == LOW)
    { game = 2;
      gameHasStarted();
    }
    if (digitalRead(buttonBlue) == LOW)
    { game = 2;
      gameHasStarted();
    }
    if (digitalRead(buttonYellow) == LOW)
    { game = 2;
      gameHasStarted();
    }
    else {
      waitToStart();
    }
  }
  while (game <= 1);
  delay(1000);
}//END OF GAME INITIATOR FUNCTION

int pickLed ()//FUNCTION WILL PICK A RANDOM LED
{
  do {
    randNumber = random(2, 6);
    digitalWrite(randNumber, HIGH);
    delay(500);
    digitalWrite(randNumber, LOW);
    delay(100);
    if (randNumber == 2)
    { ledArray[loopCounter] = 0;
      ledCounter++;
    }
    if (randNumber == 3)
    { ledArray[loopCounter] = 1;
      ledCounter++;
    }
    if (randNumber == 4)
    { ledArray[loopCounter] = 2;
      ledCounter++;
    }
    if (randNumber == 5)
    { ledArray[loopCounter] = 3;
      ledCounter++;
    }
  }
  while (ledCounter < loopCounter);
  ledPrompt();//signals for input after it's done picking the LEDs for each round
  wait == 1;
}//END OF PICKLED FUNCTION

int waitForInput ()//FUNCTION WILL WAIT FOR USER INPUT OR END GAME AFTER 10 SECONS OF NO INPUT
{
  do
  {
    if (digitalRead(buttonRed) == LOW)
    { digitalWrite(r, HIGH);
      inputCounter++;
      delay(150);
      digitalWrite(r, LOW);
      delay(150);
      buttonArray[loopCounter] = 0;
    }
    if (digitalRead(buttonYellow) == LOW)
    { digitalWrite(y, HIGH);
      inputCounter++;
      delay(150);
      digitalWrite(y, LOW);
      delay(150);
      buttonArray[loopCounter] = 1;
    }
    if (digitalRead(buttonBlue) == LOW)
    { digitalWrite(b, HIGH);
      inputCounter++;
      delay(150);
      digitalWrite(b, LOW);
      delay(150);
      buttonArray[loopCounter] = 2;
    }
    if (digitalRead(buttonGreen) == LOW)
    { digitalWrite(g, HIGH);
      inputCounter++;
      delay(150);
      digitalWrite(g, LOW);
      delay(150);
      buttonArray[loopCounter] = 3;
    }
    else {
      wait++; //the wait counter is incremented each time the loop reads all 4 input and no input has been made
      delay(250);
    }//the delay here adds 1/4th of a second each time no input is made (every 4 loop here is 1 second);

    if (wait > 40) //40 divided by 0.25 = 10 seconds of wait
    {
      pass = 0;
      fail();
    } //after waiting 10 seconds for input the game automatically fails.
  }
  while (inputCounter < loopCounter);//WAIT FOR INPUT
}   //END OF WAIT_FOR_INPUT FUNCTION

int scoreInput ()//START OF SCORE_INPUT FUNCTION
{ if (memcmp(ledArray, buttonArray, sizeof(ledArray)) == 0)
  {
    delay(1000);
    loopCounter++;
    ledCounter = 0;
    inputCounter = 0;
    game++;
    pass = 2;
  }
  else
  {
    loopCounter = 0;
    ledCounter = 0;
    inputCounter = 0;
    pass = 0;
  }
}
//END OF SCORE_INPUT FUNCTION

void setup ()
{ randomSeed(analogRead(0));
  pinMode (r, OUTPUT);
  pinMode (y, OUTPUT);
  pinMode (b, OUTPUT);
  pinMode (g, OUTPUT);
  pinMode (buttonRed, INPUT_PULLUP);
  pinMode (buttonYellow, INPUT_PULLUP);
  pinMode (buttonGreen, INPUT_PULLUP);
  pinMode (buttonBlue, INPUT_PULLUP);
  pinMode (buttonRed, INPUT);
  pinMode (buttonYellow, INPUT);
  pinMode (buttonGreen, INPUT);
  pinMode (buttonBlue, INPUT);
  pinMode (x, OUTPUT);
  game = 0;
  waiting = 0;
  loopCounter = 1;
  randNumber = 0;
  ledCounter = 0;
  inputCounter = 0;
  pass = 2;
  timeUp = 2;
  initiate();
}


void loop ()//by using functions, the void loop section here is very short.
{
  do {
    pickLed();
    waitForInput();
    scoreInput();
    if (loopCounter > 4)//states the game should end after round 10
    { youWin();
      pass = 0;
    }
  }
  while (pass > 1); // keeps the game going until round 10 or fail
  initiate();
}

If someone asks you to teach them how to drive, they're not asking you to point out the chip in the paint on their fender.

A learner driver can go a surprisingly long way with a flat tyre though.

Chipped paint won't ever bite you in the ass.

here are some parts of this code that i"m not using and this is still a rough draft.

In that case, you're just lowering the signal-to-noise ratio - we don't want to see those parts, and neither do you.
That's how development works.

Here's the last thing you do in "setup()" initiate();
Here's one of the last things "initiate ()" does before it starts looping

ledArray[55] = 0;
  buttonArray[100] = 0;

Do you know what damage that does?

No.

Me neither.

(in case you still haven't got it, how do you write to the 56th element of a ten element array, or the 101st element of a ten element array?)

TheMemberFormerlyKnownAsAWOL:
A learner driver can go a surprisingly long way with a flat tyre though.

Chipped paint won't ever bite you in the ass.
In that case, you're just lowering the signal-to-noise ratio - we don't want to see those parts, and neither do you.
That's how development works.

Here's the last thing you do in "setup()"   initiate();
Here's one of the last things "initiate ()" does before it starts looping

ledArray[55] = 0;

buttonArray[100] = 0;




Do you know what damage that does?

No.

Me neither.

(in case you still haven't got it, how do you write to the 56th element of a ten element array, or the 101st element of a ten element array?)

No clue. How do you compare button presses to match the color of LED associated with that button when the LEDs are supposed to be random?

You still need to fix this:

 ledArray[55] = 0;
  buttonArray[100] = 0;

Memory corruption == crash

Shouldn't all of your ledArray[loopCounter] = be ledArray[ledCounter] = and buttonArray[loopCounter] be buttonArray[inputCounter]? Otherwise you only write to one element of the array every time. Indeed when loopCounter is 10 you will be writing past the end of the arrays and corrupting memory.

int pickLed ()//FUNCTION WILL PICK A RANDOM LED
{
  do {
    randNumber = random(2, 6);
    digitalWrite(randNumber, HIGH);
    delay(500);
    digitalWrite(randNumber, LOW);
    delay(100);
    if (randNumber == 2)
    { ledArray[loopCounter] = 0;
      ledCounter++;
    }
    if (randNumber == 3)
    { ledArray[loopCounter] = 1;
      ledCounter++;
    }
    if (randNumber == 4)
    { ledArray[loopCounter] = 2;
      ledCounter++;
    }
    if (randNumber == 5)
    { ledArray[loopCounter] = 3;
      ledCounter++;
    }
  }
  while (ledCounter < loopCounter);
  ledPrompt();//signals for input after it's done picking the LEDs for each round
  wait == 1;
}//END OF PICKLED FUNCTION

int waitForInput ()//FUNCTION WILL WAIT FOR USER INPUT OR END GAME AFTER 10 SECONS OF NO INPUT
{
  do
  {
    if (digitalRead(buttonRed) == LOW)
    { digitalWrite(r, HIGH);
      inputCounter++;
      delay(150);
      digitalWrite(r, LOW);
      delay(150);
      buttonArray[loopCounter] = 0;
    }
    if (digitalRead(buttonYellow) == LOW)
    { digitalWrite(y, HIGH);
      inputCounter++;
      delay(150);
      digitalWrite(y, LOW);
      delay(150);
      buttonArray[loopCounter] = 1;
    }
    if (digitalRead(buttonBlue) == LOW)
    { digitalWrite(b, HIGH);
      inputCounter++;
      delay(150);
      digitalWrite(b, LOW);
      delay(150);
      buttonArray[loopCounter] = 2;
    }
    if (digitalRead(buttonGreen) == LOW)
    { digitalWrite(g, HIGH);
      inputCounter++;
      delay(150);
      digitalWrite(g, LOW);
      delay(150);
      buttonArray[loopCounter] = 3;
    }
    else {
      wait++; //the wait counter is incremented each time the loop reads all 4 input and no input has been made
      delay(250);
    }//the delay here adds 1/4th of a second each time no input is made (every 4 loop here is 1 second);

    if (wait > 40) //40 divided by 0.25 = 10 seconds of wait
    {
      pass = 0;
      fail();
    } //after waiting 10 seconds for input the game automatically fails.
  }
  while (inputCounter < loopCounter);//WAIT FOR INPUT
}   //END OF WAIT_FOR_INPUT FUNCTION
int ledArray[10];
int buttonArray[10];
int loopCounter;
int ledCounter;
int inputCounter;
int game;
int waiting;
int pass;
int wait;
int timeUp;

//ALL THE BUTTONS & LEDS ARE GIVEN NAMES HERE SO THEY'RE EASIER TO REFERENCE
const int buttonRed = 6;
const int buttonYellow = 7;
const int buttonGreen = 9;
const int buttonBlue = 8;
const int r = 2;
const int y = 3;
const int b = 4;
const int g = 5;
const int x = 10;//LED ON PIN 10 IS THE WHITE LED USED FOR PROMPTS


///USED FOR PROCESSING AND COMPARING INPUTS
int randNumber;
int array_Cmp;

void youWin ()
{ digitalWrite(2, HIGH);
  delay(100);
  digitalWrite(2, LOW);
  delay(100);
  digitalWrite(3, HIGH);
  delay(100);
  digitalWrite(3, LOW);
  delay(100);
  digitalWrite(4, HIGH);
  delay(100);
  digitalWrite(4, LOW);
  delay(100);
  digitalWrite(5, HIGH);
  delay(100);
  digitalWrite(5, LOW);
  delay(100);
}

void ledPrompt()
//prompts player for inout during game after
//the LEDs have been picked randomly each round
{ digitalWrite(x, HIGH);
  delay(1000);
  digitalWrite(x, LOW);
  delay(50);
}

void gameHasStarted()
//LED prompt after first button
//is pushed to start the game
{
  digitalWrite(10, HIGH);
  delay(1000);
  digitalWrite(10, LOW);
  delay(100);
}

void fail() //LED sequence when the wrong input is entered
{ digitalWrite(2, HIGH);
  delay(1000);
  digitalWrite(3, HIGH);
  delay(1000);
  digitalWrite(4, HIGH);
  delay(1000);
  digitalWrite(5, HIGH);
  delay(1000);
  digitalWrite(2, LOW);
  delay(50);
  digitalWrite(3, LOW);
  delay(50);
  digitalWrite(4, LOW);
  delay(50);
  digitalWrite(5, LOW);
  delay(50);
}

void waitToStart() //cycles through LEDs while waiting to start the game
{ digitalWrite(2, HIGH);
  delay(250);
  digitalWrite(2, LOW);
  delay(250);
  digitalWrite(3, HIGH);
  delay(250);
  digitalWrite(3, LOW);
  delay(250);
  digitalWrite(4, HIGH);
  delay(250);
  digitalWrite(4, LOW);
  delay(250);
  digitalWrite(5, HIGH);
  delay(250);
  digitalWrite(5, LOW);
  delay(250);
}

int initiate()//FUNCTION WAITS FOR ANY OF 4 BUTTONS TO BE PUSHED TO START THE GAME
{ game = 0;
  waiting = 0;
  loopCounter = 1;
  randNumber = 0;
  ledCounter = 0;
  inputCounter = 0;
  pass = 2;
  //FUNCTION INCLUDES ALL OF THE ASSUMPTIONS NEEDED TO EXECUTE THE 1ST ROUND PROPERLY
  do {
    if (digitalRead(buttonRed) == LOW)
    { game = 2;
      gameHasStarted();
    }
    if (digitalRead(buttonGreen) == LOW)
    { game = 2;
      gameHasStarted();
    }
    if (digitalRead(buttonBlue) == LOW)
    { game = 2;
      gameHasStarted();
    }
    if (digitalRead(buttonYellow) == LOW)
    { game = 2;
      gameHasStarted();
    }
    else {
      waitToStart();
    }
  }
  while (game <= 1);
  delay(1000);
}//END OF GAME INITIATOR FUNCTION

int pickLed ()//FUNCTION WILL PICK A RANDOM LED
{
  do {
    randNumber = random(2, 6);
    digitalWrite(randNumber, HIGH);
    delay(500);
    digitalWrite(randNumber, LOW);
    delay(100);
    if (randNumber == 2)
    { ledArray[loopCounter] = 0;
      ledCounter++;
    }
    if (randNumber == 3)
    { ledArray[loopCounter] = 1;
      ledCounter++;
    }
    if (randNumber == 4)
    { ledArray[loopCounter] = 2;
      ledCounter++;
    }
    if (randNumber == 5)
    { ledArray[loopCounter] = 3;
      ledCounter++;
    }
  }
  while (ledCounter < loopCounter);
  ledPrompt();//signals for input after it's done picking the LEDs for each round
  wait == 1;
}//END OF PICKLED FUNCTION

int waitForInput ()//FUNCTION WILL WAIT FOR USER INPUT OR END GAME AFTER 10 SECONS OF NO INPUT
{
  do
  {
    if (digitalRead(buttonRed) == LOW)
    { digitalWrite(r, HIGH);
      inputCounter++;
      delay(150);
      digitalWrite(r, LOW);
      delay(150);
      buttonArray[loopCounter] = 0;
    }
    if (digitalRead(buttonYellow) == LOW)
    { digitalWrite(y, HIGH);
      inputCounter++;
      delay(150);
      digitalWrite(y, LOW);
      delay(150);
      buttonArray[loopCounter] = 1;
    }
    if (digitalRead(buttonBlue) == LOW)
    { digitalWrite(b, HIGH);
      inputCounter++;
      delay(150);
      digitalWrite(b, LOW);
      delay(150);
      buttonArray[loopCounter] = 2;
    }
    if (digitalRead(buttonGreen) == LOW)
    { digitalWrite(g, HIGH);
      inputCounter++;
      delay(150);
      digitalWrite(g, LOW);
      delay(150);
      buttonArray[loopCounter] = 3;
    }
    else {
      wait++; //the wait counter is incremented each time the loop reads all 4 input and no input has been made
      delay(250);
    }//the delay here adds 1/4th of a second each time no input is made (every 4 loop here is 1 second);

    if (wait > 40) //40 divided by 0.25 = 10 seconds of wait
    {
      pass = 0;
      fail();
    } //after waiting 10 seconds for input the game automatically fails.
  }
  while (inputCounter < loopCounter);//WAIT FOR INPUT
}   //END OF WAIT_FOR_INPUT FUNCTION

int scoreInput ()//START OF SCORE_INPUT FUNCTION
{ if (memcmp(ledArray, buttonArray, sizeof(ledArray)) == 0)
  {
    delay(1000);
    loopCounter++;
    ledCounter = 0;
    inputCounter = 0;
    game++;
    pass = 2;
  }
  else
  {
    loopCounter = 0;
    ledCounter = 0;
    inputCounter = 0;
    pass = 0;
  }
}
//END OF SCORE_INPUT FUNCTION

void setup ()
{ randomSeed(analogRead(0));
  pinMode (r, OUTPUT);
  pinMode (y, OUTPUT);
  pinMode (b, OUTPUT);
  pinMode (g, OUTPUT);
  pinMode (buttonRed, INPUT_PULLUP);
  pinMode (buttonYellow, INPUT_PULLUP);
  pinMode (buttonGreen, INPUT_PULLUP);
  pinMode (buttonBlue, INPUT_PULLUP);
  pinMode (buttonRed, INPUT);
  pinMode (buttonYellow, INPUT);
  pinMode (buttonGreen, INPUT);
  pinMode (buttonBlue, INPUT);
  pinMode (x, OUTPUT);
  game = 0;
  waiting = 0;
  loopCounter = 1;
  randNumber = 0;
  ledCounter = 0;
  inputCounter = 0;
  pass = 2;
  timeUp = 2;
  initiate();
}


void loop ()//by using functions, the void loop section here is very short.
{
  do {
    pickLed();
    waitForInput();
    scoreInput();
    if (loopCounter > 4)//states the game should end after round 10
    { youWin(); 
      pass = 0;
    }
  }
  while (pass > 1); // keeps the game going until round 10 or fail
  initiate();
}

I did already. I did it that way because of something else I got from this same forum. But yeah I've fixed it already.
I don't want to have to completely start over. I understand what arrays do but maybe I don't understand how they work. If I create an array to store whatever button is lit( which I can do very easily, how would I determine if the right button has been pressed (not to be confused for the right amount of button). My issue is that the LEDs will be randomized because they're an output, but the input (buttons) clearly won't be random.

Also in the code below your comparison should only compare the number of loops you have made. So, instead of memcmp(ledArray, buttonArray, sizeof(ledArray)) you should have memcmp(ledArray, buttonArray, loopCounter)

int scoreInput ()//START OF SCORE_INPUT FUNCTION
{ if (memcmp(ledArray, buttonArray, sizeof(ledArray)) == 0)
  {
    delay(1000);
    loopCounter++;
    ledCounter = 0;
    inputCounter = 0;
    game++;
    pass = 2;
  }
  else
  {
    loopCounter = 0;
    ledCounter = 0;
    inputCounter = 0;
    pass = 0;
  }
}
//END OF SCORE_INPUT FUNCTION

ToddL1962:
Also in the code below your comparison should only compare the number of loops you have made. So, instead of memcmp(ledArray, buttonArray, sizeof(ledArray)) you should have memcmp(ledArray, buttonArray, loopCounter)

int scoreInput ()//START OF SCORE_INPUT FUNCTION

{ if (memcmp(ledArray, buttonArray, sizeof(ledArray)) == 0)
  {
    delay(1000);
    loopCounter++;
    ledCounter = 0;
    inputCounter = 0;
    game++;
    pass = 2;
  }
  else
  {
    loopCounter = 0;
    ledCounter = 0;
    inputCounter = 0;
    pass = 0;
  }
}
//END OF SCORE_INPUT FUNCTION

the code is meant to compare the buttons pressed to the LEDs that were lit. It's not about how many loops. Maybe I misunderstand?

ToddL1962:
Also in the code below your comparison should only compare the number of loops you have made. So, instead of memcmp(ledArray, buttonArray, sizeof(ledArray)) you should have memcmp(ledArray, buttonArray, loopCounter)

"loopCounter" * sizeof int", surely?

TheMemberFormerlyKnownAsAWOL:
"loopCounter" * sizeof int", surely?

Nope...that code worked perfectly for what it was supposed to do so not going to change it. Again, this is the issue I'm tackling now....

I don't want to have to completely start over. I understand what arrays do but maybe I don't understand how they work. If I create an array to store whatever button is lit( which I can do very easily, how would I determine if the right button has been pressed (not to be confused for the right amount of button). My issue is that the LEDs will be randomized because they're an output, but the input (buttons) clearly won't be random.

TheMemberFormerlyKnownAsAWOL:
"loopCounter" * sizeof int", surely?

You are correct. loopCounter*sizeof(int). I could have ruined his project with that mistake.

How do you compare a random output (that's going to change everytime the game is played) to 4 fixed inputs?

premobowei:
Nope...that code worked perfectly for what it was supposed to do so not going to change it. Again, this is the issue I'm tackling now....

I don't want to have to completely start over. I understand what arrays do but maybe I don't understand how they work. If I create an array to store whatever button is lit( which I can do very easily, how would I determine if the right button has been pressed (not to be confused for the right amount of button). My issue is that the LEDs will be randomized because they're an output, but the input (buttons) clearly won't be random.

Ok... in your code you are storing a 0 for Red LED and a 0 for Red Button, a 1 for a Yellow LED and a 1 for a Yellow button and so on. When you compare your arrays then those should match if the button is correct. However, as I pointed out previously, you need to use the ledCounter as the array subscript for LEDs and the inputCounter as the array subscript for the buttons if you want this compare to work properly.

I'm pretty sure everyone has lost interested in helping due to your stubborn refusal to fix the array boundary error that will surely cause problems sooner rather than later. Now we're just watching with morbid curiosity like some might watch a train wreck.

Personally, I’d sh*t can your whole approach. Too ugly. I’d use a struct to pair the Led Pins and Button Pins together. Then, have an array of these to define all the button / LEDs you’re using. Then your random sequence would just be an array of random indices into the Led / Button array. But, I’ve lost interest due to your bad attitude.

struct LedButtonPair {
  uint8_t ledPin;
  uint8_t buttonPin;
};

const LedButtonPair pairs [] = {
  {2, 8}, {3, 9}, {4, 10}, {5, 11}    // Or what ever. I don't know what your Led / Button pins are or how many pairs you have
};
const uint8_t numPairs = sizeof(pairs)/sizeof(pairs[0]);

uint8_t sequenceCounter;

uint8_t sequence[50];   // say maximun of 50 random steps in a sequence
sequence[sequenceCounter++] = random(0, numPairs);    // pick the next random step in the sequence

ToddL1962:
Ok... in your code you are storing a 0 for Red LED and a 0 for Red Button, a 1 for a Yellow LED and a 1 for a Yellow button and so on. When you compare your arrays then those should match if the button is correct. However, as I pointed out previously, you need to use the ledCounter as the array subscript for LEDs and the inputCounter as the array subscript for the buttons if you want this compare to work properly.

I'm using these counters currently to count the number of input in order to tell it when to break from reading or waiting for inputs. And I'm using the ledCounter to tell it when to break from selecting LEDs.

Could you give one example?
So I would read input using do_while as I already have it, and then use an array to record input, then I would compare. My thing i

gfvalvo:
I'm pretty sure everyone has lost interested in helping due to your stubborn refusal to fix the array boundary error that will surely cause problems sooner rather than later. Now we're just watching with morbid curiosity like some might watch a train wreck.

Personally, I’d sh*t can your whole approach. Too ugly. I’d use a struct to pair the Led Pins and Button Pins together. Then, have an array of these to define all the button / LEDs you’re using. Then your random sequence would just be an array of random indices into the Led / Button array. But, I’ve lost interest due to your bad attitude.

struct LedButtonPair {

uint8_t ledPin;
  uint8_t buttonPin;
};

const LedButtonPair pairs [] = {
  {2, 8}, {3, 9}, {4, 10}, {5, 11}    // Or what ever. I don't know what your Led / Button pins are or how many pairs you have
};
const uint8_t numPairs = sizeof(pairs)/sizeof(pairs[0]);

uint8_t sequenceCounter;

uint8_t sequence[50];  // say maximun of 50 random steps in a sequence






sequence[sequenceCounter++] = random(0, numPairs);    // pick the next random step in the sequence

I literally fixed it? what are you talking about?
I also didn't know there was any such thing as the struct you described. Makes so much sense. I've wondered but I should've asked. If you look up or to the last page, I did fix it.

gfvalvo:
I'm pretty sure everyone has lost interested in helping due to your stubborn refusal to fix the array boundary error that will surely cause problems sooner rather than later. Now we're just watching with morbid curiosity like some might watch a train wreck.

Personally, I’d sh*t can your whole approach. Too ugly. I’d use a struct to pair the Led Pins and Button Pins together. Then, have an array of these to define all the button / LEDs you’re using. Then your random sequence would just be an array of random indices into the Led / Button array. But, I’ve lost interest due to your bad attitude.

struct LedButtonPair {

uint8_t ledPin;
  uint8_t buttonPin;
};

const LedButtonPair pairs [] = {
  {2, 8}, {3, 9}, {4, 10}, {5, 11}    // Or what ever. I don't know what your Led / Button pins are or how many pairs you have
};
const uint8_t numPairs = sizeof(pairs)/sizeof(pairs[0]);

uint8_t sequenceCounter;

uint8_t sequence[50];  // say maximun of 50 random steps in a sequence






sequence[sequenceCounter++] = random(0, numPairs);    // pick the next random step in the sequence

Thanks for this.
How would I execute the first randomization then?
I'm trying to understand the language with this structure.
Could you give an example?

//ALL THE BUTTONS & LEDS ARE GIVEN NAMES HERE SO THEY'RE EASIER TO REFERENCE
const int buttonRed = 6;
const int buttonYellow = 7;
const int buttonGreen = 9;
const int buttonBlue = 8;
const int r = 2;
const int y = 3;
const int b = 4;
const int g = 5;
const int x = 10;//LED ON PIN 10 IS THE WHITE LED USED FOR PROMPTS


struct LedButtonPair {
  uint8_t ledPin;
  uint8_t buttonPin;
};

const LedButtonPair pairs [] = {
  {2, 6}, {3, 7}, {4, 8}, {5, 9}    // Or what ever. I don't know what your Led / Button pins are or how many pairs you have
};
const uint8_t numPairs = sizeof(pairs) / sizeof(pairs[0]);
uint8_t sequenceCounter;

uint8_t sequence[10];

void setup()
{ pinMode (r, OUTPUT);
  pinMode (y, OUTPUT);
  pinMode (b, OUTPUT);
  pinMode (g, OUTPUT);
  pinMode (buttonRed, INPUT_PULLUP);
  pinMode (buttonYellow, INPUT_PULLUP);
  pinMode (buttonGreen, INPUT_PULLUP);
  pinMode (buttonBlue, INPUT_PULLUP);
  pinMode (buttonRed, INPUT);
  pinMode (buttonYellow, INPUT);
  pinMode (buttonGreen, INPUT);
  pinMode (buttonBlue, INPUT);
  pinMode (x, OUTPUT);
}
void loop()
{
  sequence[sequenceCounter++] = random(0, numPairs);
  digitalWrite(numPairs, HIGH);
  delay(500);
  digitalWrite(numPairs, LOW);
  delay(500);
}

I got this to light up an LED. Is this on the right track? It also seems to be lighting up the same LED every time?

Is it the blue LED by any chance?

Or have I misunderstood the meaning of the constant "b"?

TheMemberFormerlyKnownAsAWOL:
Is it the blue LED by any chance?

Or have I misunderstood the meaning of the constant "b"?

Yes, How did you know?