I need some help with a nRF24L01 bug

in the game controller you don't put end = true; (better than HIGH for a boolean) when you have won or pressed too fast.

          if (bericht.ontvangerUID == 1 && bericht.alleCons == 0) //Gaat het bericht naar een speciafieke con?
          {
            if (bericht.command == 'F') //If the incoming message is 'F' it means you have pressed too fast.
            {
              tone(buzz, 1000); //normaal laten trillen
              digitalWrite(vibr, HIGH);
              delay(1000);
              noTone(buzz);
              digitalWrite(vibr, LOW);
            }
            else if (bericht.command == 'T')//If the incoming message is 'T' it means you are the winner.
            {
              tone(buzz, 1000);
              digitalWrite(vibr, HIGH);
            }
          }

instead of

 isGedrukt = LOW; //The next game the button will be able to be pressed again. Its a reset.

you should wait for the button to be realeased

while(digitalRead(knop) == LOW); // active wait
isGedrukt = false;

On the hub side, how is your button wired? -> I see it's an INPUT_PULLUP but you check if it's pressed like this:
if (digitalRead(knopM) == HIGH) //If the button is pressed.
why isn't that LOW since you are in INPUT_PULLUP mode?

Always use unsigned long for your millis() related variables like tijdTimer or huidigeTijd or you might get in trouble if you keep the game running for 25 days :wink:

I think your loop is more complex than it should be, in my view you should always listen to messages and write a small state machine to decide what to do with the message or button press

Hi hi,

Sorry that I didn't respond for some time. Vacation and some other things didn't let me continue with the project.
I have some great news btw: the program works! :fireworks:
I did change the LOW and HIGH with true and false.
I also changed the huidigeTijd with a unsigned long.

I don't really know what did it, I think the high and low. But it works for more then 7 times in a row and so on.
I have not tested the program with two controllers but I have a feeling that those will work too.
Thanks for the help, now I can hopefully write the full code before the end of the semester.

As for the last few sentences: I think your loop is more complex than it should be, in my view you should always listen to messages and write a small state machine to decide what to do with the message or button press

Do you mean to write the main loop with commands that send the program to void functions?

Good to hear it’s working

I meant that the loop should be event driven (message, buttons, timeout,…) and a small state machine decides what to do with the event. Blocking code is never great.

1 Like

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.