Skip to main content
added 22 characters in body
Source Link
Swedgin
  • 241
  • 2
  • 9

Looking into your for-loop:

for (int i = 1; i <= ROUNDS; i++)
  {

    // Write sequence
    digitalWriteGeneric(i);

    // Read sequence
    bool wait = 1;
    int expected = Sequence[i - 1];
    while (wait)
      {
        int value = digitalReadGeneric();
        if (expected == value)
          {
            Serial.print("Right");
            wait = 0;
            break;

            // Setting vlag to false will exit the while loop
            // break will also exit the while loop
            // so only need to do 1 of the 2
            // but then you won't be able to read anymore, it exited the while-loop
          }
      }
  }

You only check the first button, and if this one is correct you go out of the while loop, ending the reading.

You can change the type of variable wait to an uint8_t (init to 0) and if the value is right, increment wait. The while-loop becomes: while (wait < i) {}. You can use break to stop reading when the player clicked a wrong button.

To see if the player did the sequence correctly: if (wait == i) {"GOOD";} else {"BAD";}

Looking into your for-loop:

for (int i = 1; i <= ROUNDS; i++)
  {

    // Write sequence
    digitalWriteGeneric(i);

    bool wait = 1;
    int expected = Sequence[i - 1];
    while (wait)
      {
        int value = digitalReadGeneric();
        if (expected == value)
          {
            Serial.print("Right");
            wait = 0;
            break;

            // Setting vlag to false will exit the while loop
            // break will also exit the while loop
            // so only need to do 1 of the 2
            // but then you won't be able to read anymore, it exited the while-loop
          }
      }
  }

You only check the first button, and if this one is correct you go out of the while loop, ending the reading.

You can change the type of variable wait to an uint8_t (init to 0) and if the value is right, increment wait. The while-loop becomes: while (wait < i) {}. You can use break to stop reading when the player clicked a wrong button.

To see if the player did the sequence correctly: if (wait == i) {"GOOD";} else {"BAD";}

Looking into your for-loop:

for (int i = 1; i <= ROUNDS; i++)
  {

    // Write sequence
    digitalWriteGeneric(i);

    // Read sequence
    bool wait = 1;
    int expected = Sequence[i - 1];
    while (wait)
      {
        int value = digitalReadGeneric();
        if (expected == value)
          {
            Serial.print("Right");
            wait = 0;
            break;

            // Setting vlag to false will exit the while loop
            // break will also exit the while loop
            // so only need to do 1 of the 2
            // but then you won't be able to read anymore, it exited the while-loop
          }
      }
  }

You only check the first button, and if this one is correct you go out of the while loop, ending the reading.

You can change the type of variable wait to an uint8_t (init to 0) and if the value is right, increment wait. The while-loop becomes: while (wait < i) {}. You can use break to stop reading when the player clicked a wrong button.

To see if the player did the sequence correctly: if (wait == i) {"GOOD";} else {"BAD";}

added 2 characters in body
Source Link
Swedgin
  • 241
  • 2
  • 9

Looking into your for-loop:

for (int i = 1; i <= ROUNDS; i++)
  {

    // Write sequence
    digitalWriteGeneric(i);

    bool wait = 1;
    int expected = Sequence[i - 1];
    while (wait)
      {
        int value = digitalReadGeneric();
        if (expected == value)
          {
            Serial.print("Right");
            wait = 0;
            break;

            // Setting vlag to false will exit the while loop
            // break will also exit the while loop
            // so only need to do 1 of the 2
            // but then you won't be able to read anymore, it exited the while-loop
          }
      }
  }

You only check the first button, and if this one is correct you go out of the while loop, ending the reading.

You can change the type of variable wait to an uint8_t (init to 0) and if the value is right, increment wait. The while-loop becomes: while (wait < i) {}. You can use break to stop reading when the player clicked a wrong button.

To see if the player did the sequence correctly: if (wait == i) {"GOOD""GOOD";} else {"BAD""BAD";}

Looking into your for-loop:

for (int i = 1; i <= ROUNDS; i++)
  {

    // Write sequence
    digitalWriteGeneric(i);

    bool wait = 1;
    int expected = Sequence[i - 1];
    while (wait)
      {
        int value = digitalReadGeneric();
        if (expected == value)
          {
            Serial.print("Right");
            wait = 0;
            break;

            // Setting vlag to false will exit the while loop
            // break will also exit the while loop
            // so only need to do 1 of the 2
            // but then you won't be able to read anymore, it exited the while-loop
          }
      }
  }

You only check the first button, and if this one is correct you go out of the while loop, ending the reading.

You can change the type of variable wait to an uint8_t (init to 0) and if the value is right, increment wait. The while-loop becomes: while (wait < i) {}. You can use break to stop reading when the player clicked a wrong button.

To see if the player did the sequence correctly: if (wait == i) {"GOOD"} else {"BAD"}

Looking into your for-loop:

for (int i = 1; i <= ROUNDS; i++)
  {

    // Write sequence
    digitalWriteGeneric(i);

    bool wait = 1;
    int expected = Sequence[i - 1];
    while (wait)
      {
        int value = digitalReadGeneric();
        if (expected == value)
          {
            Serial.print("Right");
            wait = 0;
            break;

            // Setting vlag to false will exit the while loop
            // break will also exit the while loop
            // so only need to do 1 of the 2
            // but then you won't be able to read anymore, it exited the while-loop
          }
      }
  }

You only check the first button, and if this one is correct you go out of the while loop, ending the reading.

You can change the type of variable wait to an uint8_t (init to 0) and if the value is right, increment wait. The while-loop becomes: while (wait < i) {}. You can use break to stop reading when the player clicked a wrong button.

To see if the player did the sequence correctly: if (wait == i) {"GOOD";} else {"BAD";}

Source Link
Swedgin
  • 241
  • 2
  • 9

Looking into your for-loop:

for (int i = 1; i <= ROUNDS; i++)
  {

    // Write sequence
    digitalWriteGeneric(i);

    bool wait = 1;
    int expected = Sequence[i - 1];
    while (wait)
      {
        int value = digitalReadGeneric();
        if (expected == value)
          {
            Serial.print("Right");
            wait = 0;
            break;

            // Setting vlag to false will exit the while loop
            // break will also exit the while loop
            // so only need to do 1 of the 2
            // but then you won't be able to read anymore, it exited the while-loop
          }
      }
  }

You only check the first button, and if this one is correct you go out of the while loop, ending the reading.

You can change the type of variable wait to an uint8_t (init to 0) and if the value is right, increment wait. The while-loop becomes: while (wait < i) {}. You can use break to stop reading when the player clicked a wrong button.

To see if the player did the sequence correctly: if (wait == i) {"GOOD"} else {"BAD"}