-1
boolean test(void)
{
  if (light==0)
  {
     return false;
  }
  ;
  if ( BIT_IS_SET(PINB, 2) ) 
  {
    if ((colour==1 && light==4)||(colour==0 && light==5))
    {
       mark=mark+100;
       light=0;
       return true;
    }
    else
    {
      life=life-1;
      analogWrite(SPEAKERPIN,200);
      delay(10);
      analogWrite(SPEAKERPIN,0);
      light=0;
      return true;
    }
    ;
  }
  delay(10);
  if(BIT_IS_SET(PINB, 3)) 
  {
    if ((colour==1 && light==5)||(colour==0 && light==4))
    {
      mark=mark+100;
       light=0;
       return true;
    }
    else
    {
      life=life-1;
      analogWrite(SPEAKERPIN,200);
      delay(10);
      analogWrite(SPEAKERPIN,0);
      light=0;
      return true;
    }
  }
  return false;
}
void loop()
{
  game();
  while(test()==false)
  {
  }
  ;
  if(life<0)
  {
    die();
  }

the test function do not work as i throught,after click the button ,it will direcly go to the die fuction(2->-1).no mather the number of colour and light .when button pressed ,most of the time will make it repeat the test function until it die.

1 Answers1

0

The first line says

 light=0

seems likely that is where the problem is. Have you used a debugger? You do know this is an assignment statement?

light will always be set to 0 everytime you run this function.

maybe you want this?

if (light == 0)
{
  return false;
}
Hogan
  • 69,564
  • 10
  • 76
  • 117
  • the biggest proplem is no mather what is the number of light and colour, it will run everything in the game function. – lokhin sham Jun 02 '22 at 14:29
  • @lokhinsham -- I don't understand your question – Hogan Jun 02 '22 at 14:59
  • what i want : after clicking the button it check the anser by matching the colour and light but it do not work – lokhin sham Jun 02 '22 at 17:41
  • ok -- what does it mean to click on a button -- are you using a library / API? Which one? What does it mean to match the light? You don't explain any of these things -- there is no way for us to know. – Hogan Jun 02 '22 at 18:05