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
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
}
}