Comparison between pointer and integer C++ forbiden

I've posted a "Blurb" of code that is giving me an error as follows: ISO C++ forbids comparison between pointer and integer

specifically on line: if(x != sequence)...
what am I not seeing?

Blurb:

while(mistake == false)
{ //as long as no mistakes have been made remain in this loop
int currentled=random(4); // pick a random LED to light up
sequence[counter]=currentled; //assign random LED to sequence array
for(int i=0; i<=counter; i++)
{ //display sequence
//light up each LED for 1.5 seconds
} //end display sequence

for(int i=0; i<=counter; i++)
{ //repeat LED sequence through button presses
waitForInput(); //waitForInput function pauses loop() until a button is pressed
int x = button_press(); //button_press function tells us which of the four buttons has been pressed

lightled(x,250); //lightled function lights up the LED corresponding to the button just pressed for 250 milliseconds
if(x !=sequence)
{ // compares the button pressed to the value stored in the sequence array
mistake=true; // if it doesn't match we set mistake to true to end the while loop
break; // and break out of the for loop immediately
}
} // end for loop
counter++; //increment the counter to add and addional LED to the sequence
run(0); // signal the beginning of the next turn through running led lights
} //end while loop

int button_press()
{

for(int i=0; i<=3; i++)
{
switch (digitalRead(b*))*

  • {*
  • case HIGH:*
  • //no button was pressed*
  • break;*
  • case LOW:*
  • //button was pressed, return the button number*
  • return i;*
  • break;*
  • }*
  • }*
  • }*

'x' is declared as an 'int' and 'sequence' is the name of an array. Referencing 'x' returns the contents of 'x' an 2 byte integer.

Array names are pointers and resolve to the address of the first element of the array not an element of the array.

Ok, I believe then x needs to equal counter; does that sound about right? Does value x == value counter. Seems so simple ha

The comment

// compares the button pressed to the value stored in the sequence array

translates IMHO to this code:

if (x != sequence[counter])  {
    mistake=true

PS: please enclose code in code tags :wink:

Try here

Thank You, and yes I will enclose my code with proper tags, for example:
In the Below code, the WaitForInput function is not causing "pause" in the loop; instead the loop seems to begin without user input. What am I not seeing?

// define variables
int led [] = {10,11,12,13};
int b[] = {2,3,4,5};
int sequence[100];
int rounds=0;


void setup()
{
  for(int i=0; i<=3; i++)
  {
    pinMode(led[i], OUTPUT); //set LED pins as output
    pinMode(b[i], INPUT);    //set button pins as input
    digitalWrite(b[i], HIGH);//enable internal pullups
  }
  randomSeed(analogRead(0));//set random seed from unused analog input
  
}


void loop()
{
  
  WaitForInput();  //press any button to start  
  int counter = 0; //initialize counter variable to track game progress
  boolean mistake = false; //mistake variable for tracking mistakes
  
  //run(3);  //start of game
  
  while(mistake == false)//as long as no mistakes have been made remain in this loop
  {    
   int currentled= 1;  // comment out random to start just assign "1" pick a random LED to light up
   sequence[counter]=currentled; //assign random LED to sequence array
   for(int i=0; i<=counter; i++)
   { //display sequence
      lightled(currentled,1000);//light up each LED for 1.5 seconds
   }  //end display sequence
  
   for(int i=0; i<=counter; i++)//repeat LED sequence through button presses
   { 
     WaitForInput();              //waitForInput function pauses loop() until a button is pressed
     int x = button_press();        //button_press function tells us which of the four buttons has been pressed
    
     lightled(x,500);             //lightled function lights up the LED corresponding to the button just pressed for 250 milliseconds
     if(x !=sequence[counter])
     {          // compares the button pressed to the value stored in the sequence array
       mistake=true;              // if it doesn't match we set mistake to true to end the while loop
       break;                    // and break out of the for loop immediately
     }
    }                            // end for loop
   counter++;                  //increment the counter to add and addional LED to the sequence
   run(0);                     // signal the beginning of the next turn through running led lights
  }     //end while loop
  
  run(2);   //signal to the user that a mistake has been made throug a longer sequence of running lights  
  
  delay(1000);
  flash(counter-2); //signal to the user how many correct turns were accomplished
  delay(1000);
  
  //at this point the game starts over

}//end of loop()

void flash(int times)
{
  for(int flashes =0; flashes<=times; flashes++)
  {
    for(int i=0; i<=3; i++)
    {
      digitalWrite(led[i], HIGH);
    }
    delay(500);
    for(int i=0; i<=3; i++)
    {
      digitalWrite(led[i], LOW);
    }
    delay(500);
  }
}

void run(int times)
{
  for(int runs=0; runs<=times; runs++)
  {
    
    for(int i=0; i<=3; i++)
    {
      digitalWrite(led[i],HIGH);
      delay(50);
      digitalWrite(led[i],LOW);
    }
    for(int i=3; i>=0; i--){
      digitalWrite(led[i],HIGH);
      delay(50);
      digitalWrite(led[i],LOW);
    }
  }
}

int button_press()
{
  
  for(int i=0; i<=3; i++)
  {
    switch (digitalRead(b[i]))
    {
      case HIGH:
      //no button was pressed
      break;
      case LOW:
      //button was pressed, return the button number
      return i;
      break;
    }
  }
  }

void lightled(int x, int duration){
 digitalWrite(led[x],HIGH);

delay(duration);
 digitalWrite(led[x],LOW);

if(duration > 500){
   delay(duration/2);
 }
  
}

void WaitForInput()
{
  while(digitalRead(2) !=LOW && digitalRead(3) !=LOW && digitalRead(4) !=LOW && digitalRead(5) !=LOW)
 
  {
    //do nothing until a button has been pressed
  }

}

kramekram:
What am I not seeing?

Does the button pressed state correspond to a HIGH or LOW input value?

Pressed button should indicate "LOW" breaking the while statement. Correct?

Pressed button should indicate "LOW" breaking the while statement.

Yes. Assuming you have the switches wires correctly - one leg to the pin and the other leg to ground.

Your logic is wrong, though.

  while(digitalRead(2) !=LOW && digitalRead(3) !=LOW && digitalRead(4) !=LOW && digitalRead(5) !=LOW)

Since you want to exit the wait loop when one of the pins is no longer HIGH, you need to tell the compiler that.

  while(digitalRead(2) == HIGH && digitalRead(3) == HIGH && digitalRead(4) == HIGH && digitalRead(5) == HIGH)