Arduino Hangman program issue

Hello I`m making a physical hangman game and have a problem with coding.

The machine has a 5 leds in x-row and 6 leds in y-row. and has an alphabet chart like below.

0,a,b,c,0 d,e,f,g,h i,j,k,l,m n,o,p,q,r s,t,u,v,w 0,x,y,z,0

If I pick the 3rd x-row led and 2nd y-row led, the letter 'f' will be selected. The part that Im struggling with is how I can match the letters from Random String Words.. I think I need to use 'for loops' but still cant figure out. Need some help. Thank you.

String Words[] = { "STEAK", "BURGER", "SUSHI", "FRIES", "CHIPS", "BERRY", "MANGO", "MELON", "APPLE", "GRAPE"};

String GRAPE[] = { "G", "R", "A", "P", "E"};

char letter1, letter2, letter3, letter4, letter5;

//x int led1 = 3; int led2 = 4; int led3 = 5; int led4 = 6; int led5 = 7;

//y int led6 = 8; int led7 = 9; int led8 = 10; int led9 = 11; int led10 = 12; int led11 = 13;

int buttonX = 0; int buttonY = 1; int buttonEnter = 2;

int countX = 0, countY = 0;

int letterIndex = -1; int wordIndex = 0;

void setup () {

pinMode(led1, OUTPUT); pinMode(led2, OUTPUT); pinMode(led3, OUTPUT); pinMode(led4, OUTPUT); pinMode(led5, OUTPUT);

pinMode(led6, OUTPUT); pinMode(led7, OUTPUT); pinMode(led8, OUTPUT); pinMode(led9, OUTPUT); pinMode(led10, OUTPUT); pinMode(led11, OUTPUT);

pinMode(buttonX, INPUT); pinMode(buttonY, INPUT); pinMode(buttonEnter, INPUT);

randomSeed(analogRead(0)); wordIndex = random(0,10); }

void loop () { /* if( Words[ wordIndex ][ letterIndex + 1] == letter ) letterIndex ++; if(letterIndex > 4){ (Words[ wordIndex ][ letterIndex + 1] == letter); // success } */

if(letter 1 == grape[0]) { digitalWrite(led1, HIGH); } if(letter 2 == grape[1]) { digitalWrite(led2, HIGH); } if(letter 3 == grape[2]) { digitalWrite(led3, HIGH); } if(letter 4 == grape[3]) { digitalWrite(led4, HIGH); } if(letter 5 == grape[4]) { digitalWrite(led5, HIGH); }

if(countX == 1){ if(countY == 1) { letter = ' '; // nothing } else if(countY == 2) { letter = 'D'; } else if(countY == 3) { letter = 'I'; } else if(countY == 4) { letter = 'N'; } else if(countY == 5) { letter = 'S'; } else if(countY == 6) { letter = ' '; // nothing } }

if(countX == 2 && countY == 1) { letter = 'A'; } if(countX == 2 && countY == 2) { letter = 'E'; } if(countX == 2 && countY == 3) { letter = 'J'; if(countX == 2 && countY == 4) { letter = 'O'; } if(countX == 2 && countY == 5) { letter = 'T'; } if(countX == 2 && countY == 6) { letter = 'X'; }

if(countX == 3 && countY == 1) { letter = 'B'; } if(countX == 3 && countY == 2) { letter = 'F'; } if(countX == 3 && countY == 3) { letter = 'K'; } if(countX == 3 && countY == 4) { letter = 'P'; } if(countX == 3 && countY == 5) { letter = 'U'; } if(countX == 3 && countY == 6) { letter = 'Y'; }

if(countX == 4 && countY == 1) { letter = 'C'; } if(countX == 4 && countY == 2) { letter = 'G'; } if(countX == 4 && countY == 3) { letter = 'L'; } if(countX == 4 && countY == 4) { letter = 'Q'; } if(countX == 4 && countY == 5) { letter = 'V'; } if(countX == 4 && countY == 6) { letter = 'Z'; }

if(countX == 5 && countY == 1) { letter = ''; //nothing } if(countX == 5 && countY == 2) { letter = 'H'; } if(countX == 5 && countY == 3) { letter = 'M'; } if(countX == 5 && countY == 4) { letter = 'R'; } if(countX == 5 && countY == 5) { letter = 'W'; } if(countX == 5 && countY == 6) { letter = ''; //nothing }

//LED X movement int count = 0;

if( digitalRead(buttonX) == HIGH) { count ++; countX += count; digitalWrite(countX + led1, HIGH); if(countX > 4){ countX = 0; digitalWrite(led5, LOW); }else digitalWrite(countX - 1 + led1, LOW); }

count = 0; //LED Y movement if(digitalRead(buttonY) == HIGH) { count ++; countY += count; digitalWrite(countY + led5, HIGH); if(countY > 5){ countY = 0; digitalWrite(led11, LOW); }else digitalWrite(countY - 1 + led5, LOW); } } }

//enter and check if(digitalRead(buttonEnter) == HIGH) {

//match letters from Random String Words

}

//False feedback (LEDs blink for a second) /* if(wrong == true) { digitalWrite(, HIGH); delay(5000); } /* //True feedback (LED blinks 3 times) if(wrong == false) { digitalWrite(, HIGH); delay(1000); digitalWrite(, LOW); delay(1000); digitalWrite(, HIGH); delay(1000); digitalWrite(, LOW); delay(1000); digitalWrite(, HIGH); delay(1000); digitalWrite(, LOW); delay(1000); } */

If I pick the 3rd x-row led and 2nd y-row led, the letter 'f' will be selected.

But, none of your words contain the letter f. F, yes, but not f.

The part that I`m struggling with is how I can match the letters from Random String Words..

A random value will be generated. That value is an index into the Words array, selecting a String instance from the array.

While this is an interesting project, the use of the String class is completely unnecessary. Change the declaration of Words to be

char *Words[] =
{ 
  "STEAK", "BURGER", "SUSHI", "FRIES", "CHIPS",
  "BERRY", "MANGO", "MELON", "APPLE", "GRAPE"
};

Then, add another (global) variable:

char *word = NULL;

In setup, assign a valid value to word:

word = Words[wordIndex];

In loop, then, use can use strlen(word) to determine how many characters in the word, and a for loop to see if word[n] is the letter chosen.

You don't need GRAPE at all, or any of the code that deals with GRAPE.