Question: Programing In C Program Specification Write a program to implement a simple pong game using the board constructed in lab. Simulate a ball moving back
Programing In C
Program Specification
Write a program to implement a simple pong game using the board constructed in lab. Simulate a ball moving back and forth by lighting the LEDs (on the bar LED) one at a time. Use the "1" and "A" keys on the keypad as the "left" and "right" buttons. When the left button is pushed and the light is in the leftmost position, the ball (represented by the lit LED) should move to the right. Similarly, when the right button is pushed and the light is in the rightmost position, the ball should move to the left. If a button is pushed at the wrong time, the opposite player will then serve.
Program Organization
Use an enumerated type type to keep track of the current state, which will take on one of the values: left_serve, right_serve, moving_left, moving_right. First set the initial state to left_serve.
Then, in an infinite loop:
1. adjust the "state"
2. adjust the LED pattern
3. delay Adjust the state based on which button, if any, is currently pressed, the current LED pattern, and the current state. Adjust the state as follows: If the left button is pressed : the new state will be moving_right if the ball is at the leftmost position, and the new state will be right_serve otherwise.
If the right button is pressed : the new state will be moving_left if the ball is at the rightmost position, and the new state will be left_serve otherwise.
If neither button is pushed and the LED pattern is 0x00 (the ball has shifted off the end) : set the state to left_serve if the ball was last moving to the right, and set it to right_serve otherwise.
If none of the above : leave the state unchanged.
Based on the new state, adjust the LED pattern as follows: if the ball is moving_left or moving_right, then shift the position of the ball accordingly. If the state is left_serve, then place the ball in the leftmost position, and if the state is right_serve, place the ball in the rightmost position.
Delay each time around the main loop using a for loop with an empty body. The maximum count in the for loop should be adjusted (by trial and error) so that it takes approximately one second for the ball to travel from the leftmost to the rightmost position of the court.
Part 1: Pong Game on an 8-LED "Court" Implement the program as described above using an 8-LED court.
Part 2:Pong Game on a 10-LED "Court" Expand the court to use all 10 LEDs on the bar LED.
Part 3: Add a Scoreboard Add scoring, and display the score in the LCD. Add a third button to reset the score at any time. The score should be reset whenever:
the reset button is pressed, or
either player reaches a score of 15.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
