Reset Pong Game on Microcontroller with C Programming

  • Thread starter nothing909
  • Start date
  • Tags
    Game
In summary, the conversation discusses using a microcontroller to create a pong game and the need to reset the program manually after each score. The solution involves setting up a push button detection and using it to change the state of the game, either by setting a flag or toggling the reset line on the microcontroller.
  • #1
nothing909
170
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
  • #2
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.
 
  • #3
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.
 

Related to Reset Pong Game on Microcontroller with C Programming

1. How do I reset a Pong game on a Microcontroller using C programming?

To reset a Pong game on a Microcontroller using C programming, you can use a "reset" function in your code that will reset all the necessary variables and parameters to their initial values. This function can be called at any point during the game to restart the game.

2. What is the purpose of resetting a Pong game on a Microcontroller?

The purpose of resetting a Pong game on a Microcontroller is to restart the game from the beginning, allowing the player to have another chance at playing. This can also be used to fix any bugs or errors that may occur during the game.

3. How do I implement a reset function in C programming for a Pong game on a Microcontroller?

To implement a reset function in C programming for a Pong game on a Microcontroller, you will need to define the function in your code and include all the necessary variables and parameters that need to be reset. You can then call this function at any point during the game to reset the game.

4. Can I customize the reset function for my Pong game on a Microcontroller?

Yes, you can customize the reset function for your Pong game on a Microcontroller according to your specific needs. You can include additional code within the function to perform certain actions or set certain parameters to specific values.

5. Is it possible to reset a Pong game on a Microcontroller without restarting the entire program?

Yes, it is possible to reset a Pong game on a Microcontroller without restarting the entire program. This can be done by only resetting the necessary variables and parameters, rather than restarting the entire program. This can help save time and resources when playing multiple games.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
8
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Programming and Computer Science
Replies
1
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
15
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
2K
  • Programming and Computer Science
Replies
3
Views
1K
Back
Top