Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

circuit Diagram of Proteus for this code. this code from Arduino uno #include #include include include #define RESET_BUTTON 6 #define UP_BUTTON 2 #define DOWN_BUTTON 3

circuit Diagram of Proteus for this code. this code from Arduino uno
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
#include #include include include #define RESET_BUTTON 6 #define UP_BUTTON 2 #define DOWN_BUTTON 3 #define SUP_BUTTON 4 #define SDOWN_BUTTON 5 const int Y pin A1: // analog pin connected to Y output const unsigned long PADDLE_RATE = 20 const unsigned long BALL_RATE= 1; const uint8_t PADDLE_HEIGHT = 12: int playerScore = 0; int a Score = 0; int maxScore = 8 int BEEPER = 12: bool rosetBall = false; #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 | OLED display height, in pixels Declaration for an SSD1306 display connected to 12C (SDA, SCL pins) #define OLED_RESET 4 // Reset pin #for-1 sharing Arduino reset pin) Adafruit_SSD1306 display(SCREEN_WIDTH SCREEN_HEIGHT, &Wire, OLED_RESET); void drawCourt: void drawScore(): uint8_t ball_x = 64, ball_y=32; uint8_t ball_dir_x = 1, ball_dir_y=1; unsigned long ball_update unsigned long paddle_update; const uint8_t SPLAYER_X = 12 uint8_t splayer_y = 16; const uint8_t PLAYER_X = 115; uint8_t player_y = 16; void setup() { display.begin(5SD1306_SWITCHCAPVCC, Ox3C): display display; unsigned long start millis: pinMode(BEEPER, OUTPUT); pinMode(UP_BUTTON, INPUT); pinMode(DOWN_BUTTON, INPUT); pinMode(RESET_BUTTON, INPUT_PULLUP); digitalWrite(UP_BUTTON,1); digitalWrite(DOWN_BUTTON, 0); pinMode(SUP_BUTTON, INPUT); pinMode(SDOWN_BUTTON, INPUT); digitalWrite(SUP_BUTTON, 1); digitalWrite(SDOWN_BUTTON, 1); display.clear DisplayO; drawCourt(): drawScorel); while(millis() - start iffreset if(playerScore == maxScore 1 Score == maxScore) gameOver(); else display.fillScreen(BLACK): drawScore(): drawCourt: ballxs random(25,70): bally random(3,63): do ball_dir_x=random(- 12): }while[ball_dit_xo): do ( bail_dit_y= random(-12): while(ball_dit_y=0); resetBallefalse; > up_state = (digitalReadUP_BUTTON) == LOW); down_state = (digitalRead(DOWN_BUTTON) == LOW): sup_state= (digitalRead(SUP_BUTTON) -- LOW); sdown_state (digitalRead(SDOWN_BUTTON) == LOW); if(time > ball_update) { uint8_t new.x = ballx+ball_dirx uint8_t new_y=bollyball_dir_y, | Check if we hit the vertical walls if(new_X == 0 || new x==127) if(new_x==OX playerScore.at disola.fillScreen(BLACK: display.fillScreen(BLACK) soundPoint: resotBall = true; > else if(new_x -- 127) alScore=1; display.fillScreen(BLACK): soundPoint(); resetBall true; > ball_die_x=-ball_die_x new_* += ball_die_x+ ball_die_x ) 1/ Check it we hit the horizontal walls. if(new_y == 0 || new_y=63) { soundBounce(); ball_die_y-ball_di_y new_y - ball_die_y + ball_dit_y D Check if we hit the CPU paddle if(new_x== SPLAYER_X 88 new_y> splayer_y && new_ysplayer_y PADDLE_HEIGHT) ball_dir_x=-ball_dit_x new_X +ball_die_x + ball_dit_x > Check if we hit the player paddle if(new_x == PLAYER_X && newy player_y && new_y player_y . PADDLE_HEIGHT) { ball_dir_x=-ball_dir_x new_x += ball_dir_X+ ball_dirx > display.drawPixelball_x, bail_y, BLACK): display.drawPixel(new.x new, WHITE): ball x new x bally = new_y: ball_update = BALL_RATE, update = true; if(time> paddle_update) { paddle_update += PADDLE_RATE: W CPU paddle display.drawFastVLine(SPLAYER_X. splayer_y, PADDLE_HEIGHT, BLACK): const uint8_t half_paddle PADDLE_HEIGHT >> 1 if(sup_state) { splayer_y - 1 ) if(sdown_state) { splayer_y += 1; ) if(splayer_y 63) splayer_y = 63 - PADDLE_HEIGHT: display drawFastViinaSPLAYER X splayer_Y, PADDLE_HEIGHT WHITE) sup_state = sdown_state false; 1/ Player paddle display.drawFastVLine(PLAYER_X, player_Y PADDLE_HEIGHT, BLACK) if(up_state) { player_y=1 if(down_state) player_y+= up_state = down_state = false; if(player_v 63) player_y = 63 - PADDLE_HEIGHT display.drawFastvLine(PLAYER_X.player- PADDLE_HEIGHT, WHITE): update = true; if(update) display display: > void drawCourt display.drawRect(0, 0, 128, 64, WHITE); void drawScore // draw Al and player scores display.setTextSize(2): display.setTextColor (WHITE); display.setCursor(45, 0); display.printina Score: display.setCursor(75, 0); display.println(playerScore); > void game Over display.fullScreen(BLACK); if(playerScoreal Score) display.setCursor(20,4); display.setTextColor(WHITE); display.setTextSize(21: display.print("1st Won"); Jelse if (aScore > playerScore) { display.setCursor(404): display.setTextColor(WHITE): display.setTextSize 2): display.print("2nd WON": > else display.setCursor(404): display.setTextColor(WHITE): display.setTextSize(): display.print("neck and neck) delay(200): display.display: delay(2000): ai Score=playerScore = 0; PADDLE_HEIGHT, WHITE); > update = true if(update) display.display: > void drawCourt display.drawRect(0, 0, 128, 64, WHITE) void drawScore Il draw Al and player scores display.setTextSize(2) display.setTextColor(WHITE); display.setCursor(45, 0); display printin(aScore): display.setCursor(75, 0); display.println(playerScore): > void gameOver display.fillScreen(BLACK) if(playerScoreScore) display.setCursor(20,4); display.setTexColor(WHITE): display.setTextSize(2); display.print("Ist Won"); Jelse if (aScore > playerScore) ( display.setCursor(40,4) display.setTextColor(WHITE): display.setTextSize(2): display.print("2nd WON"); > elser display.setCursor(40,4): display.setTextColor(WHITE) display.setTextSize(1): display.print("neck and neck"); delay(200); display.display: delay(2000): aiScore = playerScore = 0; unsigned long start = millis; while(millis() - start void soundBounce { tone BEEPER, 500, 50); } void soundPoint { tone BEEPER, 250, 50)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

1. If you were Dawn, what decision would you make and why?

Answered: 1 week ago

Question

Provide examples of Dimensional Tables.

Answered: 1 week ago