Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO-Based Interactive Basketball Arcade Game with LCD Display

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Interactive Basketball Arcade Game with LCD Display

Circuit Documentation

Summary

The circuit in question appears to be designed for an interactive game, possibly a basketball arcade game, as suggested by the embedded code. It includes an Arduino UNO microcontroller as the central processing unit, interfaced with a 16x2 LCD for display purposes. The circuit also features input components such as a pushbutton and photocells (LDRs) for sensing light levels, which may be used to detect scoring events or player interactions. Resistors are used for various purposes, including pull-up/down configurations and voltage division.

Component List

Arduino UNO

Resistor (1k Ohms)

Resistor (10k Ohms)

Pushbutton

Photocell (LDR)

16X2 LCD

Wiring Details

Arduino UNO

Resistor (1k Ohms)

Resistor (10k Ohms)

Pushbutton

Photocell (LDR)

16X2 LCD

Documented Code

#include <LiquidCrystal.h>

int oldVal1 = 0;
int oldVal2 = 0;

int blockedPercentage = 90;

int player1Score = 0;
int player2Score = 0;

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

const int buttonPin = 7;

long maxTime = 60000; // in ms
long currentTime = 0;
int mainDelay = 250;
int displayTime = 0;

int winner = 0;

const int contrast = 13;

// Function prototypes
void intro();
void initialScreen();
void initialScreenWithClock();
void renderDisplayTime();
void readyScreen();
void resetScreen();
void resetGame();
void renderWinner();

void setup() {
  Serial.begin(9600);
  analogWrite(contrast, 10);

  pinMode(buttonPin, INPUT);

  oldVal1 = analogRead(A0);
  oldVal2 = analogRead(A1);

  resetGame();

  lcd.begin(16, 2);
  intro();

  readyScreen();

  initialScreen();
}

void loop() {
  int buttonState = digitalRead(buttonPin);
  int updatePlayersScore = 0;

  if (buttonState == HIGH) {
    Serial.println("reset");
    resetGame();
    updatePlayersScore = 1;

    resetScreen();
    readyScreen();
    initialScreen();
  }

  if (currentTime < 0) {
    renderWinner();
    return;
  }

  int value = analogRead(A0);
  float value1Percentage = ((float) value / (float) oldVal1) * 100;

  oldVal1 = value;
  
  if (value1Percentage <= blockedPercentage) {
    player1Score++;
    updatePlayersScore = 1;
  }

  int value2 = analogRead(A1);

  float value2Percentage = ((float) value2 / (float) oldVal2) * 100;
  oldVal2 =  value2;

  if (value2Percentage <= blockedPercentage) {
    player2Score++;
    updatePlayersScore = 1;
  }

  if (updatePlayersScore) {
    lcd.setCursor(0, 2);
    lcd.print("                ");
    
    Serial.println("Player 1 score: ");
    Serial.println(player1Score);
    lcd.setCursor(0, 2);
    lcd.print(player1Score);

    Serial.println("Player 2 score: ");
    Serial.println(player2Score);
    lcd.setCursor(6, 2);
    lcd.print(player2Score);

    updatePlayersScore = 0;
  }

  if (currentTime % 1000 == 0) {
    displayTime = currentTime / 1000;
  }

  renderDisplayTime();

  currentTime -= mainDelay;
  
  delay(mainDelay);
}

// Additional functions are defined below

The code provided is for an Arduino UNO microcontroller and is responsible for controlling the game logic, including scorekeeping, display updates, and handling button presses to reset the game. The LiquidCrystal library is used to interface with the 16x2 LCD display. The code includes functions for displaying an introduction, ready screen, and winner screen, as well as for managing the game's state and scores.