Reset Pong Game on Microcontroller with C Programming

  • Thread starter Thread starter nothing909
  • Start date Start date
  • Tags Tags
    Game
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 2K views
nothing909
Messages
168
Reaction score
4

Homework Statement


I'm using a microcontroller to create a pong game, but I'm completely new to C programmning. I'm mostly reusing code and adding bits in here and there rather than writing it from scratch.

I have a basic pong game working right now, but every time someone scores, I have to reset the program manually.

How do I write the code to reset the program using a button on the microcontroller so it will go back to the main function?
 
Physics news on Phys.org
That depends on how you are interfacing with the pong game. code architecture and such.
First off, you need to setup the push button detection. below is a good guide for doing it on an arudino.

https://www.arduino.cc/en/Tutorial/Button

Then you need the button to do something. depending on your architecture the best way and easiest way is to have it set a flag to change the state of your game. Check for the flag every few seconds. When the flag is detected, just go to a game end state, where you clear variables and such to get the game back to its reset state. another thing you can do if you want to cheat, just have the button toggle the reset line on the micro-controller which would be a hardware reset.