Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Resetting a game

  1. Dec 5, 2017 #1
    1. The problem statement, all variables and given/known data
    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?
  2. jcsd
  3. Dec 5, 2017 #2


    User Avatar
    Science Advisor
    Homework Helper
    Gold Member
    2017 Award

    It's been awhile since I've programmed in C. But I think there are functions to check if a key (or button) is pressed or not, returning True or False. Your microcontroller documentation may give examples.
  4. Dec 6, 2017 #3


    User Avatar
    Gold Member

    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.


    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.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted