Reset Pong Game on Microcontroller with C Programming

  • Thread starter Thread starter nothing909
  • Start date Start date
  • Tags Tags
    Game
Click For Summary
To implement a reset function for a pong game on a microcontroller using C programming, set up push button detection to monitor button presses. The button should be programmed to set a flag that indicates a game state change, which can be checked periodically. When the flag is detected, transition to a game end state, clearing necessary variables to reset the game. Alternatively, a hardware reset can be achieved by toggling the reset line on the microcontroller. Proper documentation for the microcontroller will provide additional guidance on interfacing with the game.
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
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.
 
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.
 

Similar threads

Replies
8
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 6 ·
Replies
6
Views
3K
Replies
7
Views
3K
  • · Replies 15 ·
Replies
15
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K