WHAT IS MEMORY GAME?

An arduino memory game utilizes Arduino's inputs/outputs to create an interactive, engaging memory game by processing player input to match sequences of LEDs based on memorized patterns. The components and code can be customized to create variants.

Here is the circuit diagram of the model:

Schematic diagrams are invaluable for the design, understanding, troubleshooting, sharing and evolving of electronics projects. They become a reference guide that captures all the required electrical connections in a simple visual format.




The main purpose of a circuit diagram:

  1. Visualize Connections: A circuit diagram allows you to visually map out how all the components - like the Arduino, buttons, LEDs, resistors, etc. - are interconnected. This helps plan and then clearly see the complete connections.
  2. Aid Understanding: By seeing a schematic diagram of the electrical connections and components, it becomes much easier to understand how the circuit works as a system to serve a particular purpose, rather than just a mess of wires.
  3. Troubleshoot Issues: Debugging problems during the build is simpler when you have a circuit diagram to examine. You can methodically check that each connection matches the diagram which points out mistakes.
  4. Share and Replicate: Circuit diagrams make your electronic build reproducible. You can easily share the diagram so others can replicate the project with the correct wiring.
  5. Plan Modifications: Having a baseline circuit diagram means you can plan out modifications, additions, and enhancements more easily for future iterations.


Components:

Arduino UNO R3: 

The Arduino Uno R3 is a popular open-source microcontroller board, widely used for its user-friendly design and versatility in electronics and programming projects.

Piezo:

A piezo element is a transducer that converts mechanical vibrations (such as sound waves) into electrical signals or vice versa, and it is commonly used in electronic devices for generating or detecting sound.

Resistor:

It is an electronic component with a resistance value of 1000 ohms. It limits or controls the flow of electric current in a circuit and is commonly used in electronics for various purposes, such as voltage division, current limiting, and setting bias points in transistor circuits.

Pushbutton:

A push button is a simple mechanical switch that is typically used to control an electrical circuit. It consists of a button or plunger that, when pressed, makes or breaks contact with the electrical terminals, allowing or interrupting the flow of electric current.

LED:

An LED, or Light Emitting Diode, is a semiconductor device that emits light when an electric current passes through it. LEDs are widely used in various applications, including lighting, indicators, displays, and more. It is of different colors. i have used Green, Orange, Red, Blue, and White.

Breadboard:

A breadboard is a prototyping tool for electronics, featuring a grid of interconnected holes that allow components to be easily plugged in and tested without soldering.


CODE: 

The "void setup" function in Arduino is where initialization and configuration tasks are performed for the program.

void setup()

{   

pinMode(0, OUTPUT);

    pinMode(1, OUTPUT);

    pinMode(2, OUTPUT);

    pinMode(3, OUTPUT);

    pinMode(4, OUTPUT);

    pinMode(5, OUTPUT);

    pinMode(13, INPUT);

    pinMode(12, INPUT);

    pinMode(11, INPUT);


The function "gameManager," and the curly braces {} enclose the body of the function where the actual code for managing game-related tasks would be written.


void GameManager() {

    bool notlost = true;

    int round = 1;

    while (notlost) {

    long saveD[round];

    for (int i = 1; i <= round; i++) {

    saveD[i - 1] = GameStart();

        }

    delay(1000);

        digitalWrite(0, HIGH);

        digitalWrite(1, HIGH);

        digitalWrite(2, HIGH);

        digitalWrite(3, HIGH);

        digitalWrite(4, HIGH);

        delay(1000);

        digitalWrite(0, LOW);

        digitalWrite(1, LOW);

        digitalWrite(2, LOW);

        digitalWrite(3, LOW);

        digitalWrite(4, LOW);

    for (int i = 1; i <= round; i++) {

        int currentLED = 0;

        while (digitalRead(11) == 0) {

        if (digitalRead(12) == 1) {

        digitalWrite(currentLED, LOW);

        currentLED++;

     if (currentLED >= 5) {

         currentLED = 0;

       }

         delay(100);

       }

         digitalWrite(currentLED, HIGH);

         delay(100);

       }

         digitalWrite(currentLED, LOW);

     if (currentLED != saveD[i - 1]) {

         notlost = false;

         digitalWrite(0, HIGH);

         digitalWrite(2, HIGH);

         digitalWrite(4, HIGH);

         digitalWrite(5, HIGH);

         delay(500);

         digitalWrite(0, LOW);

         digitalWrite(2, LOW);

         digitalWrite(4, LOW);

         digitalWrite(1, HIGH);

         digitalWrite(3, HIGH);

         delay(500);

         digitalWrite(1, LOW);

         digitalWrite(3, LOW);

         digitalWrite(5, LOW);

      return;

     }

         delay(200);

     }

         round++;

         tone(5, 1318.51, 100);

         delay(100);

         tone(5, 1975.53, 200);

         delay(200);

         delay(500);

      for (int i = 0; i <= 2; i++) {

      for (int j = 0; j <= 4; j++) {

          digitalWrite(j, HIGH);

          delay(50);

          digitalWrite(j, LOW);

      }

      }

          delay(1000);

      }

      }

      long GameStart() {

      long randomN = random(0, 5);

         digitalWrite(randomN, HIGH);

         delay(1000);

         digitalWrite(randomN, LOW);

         delay(500);

      return randomN;

      }


In the Arduino programming environment, "void loop" refers to the main execution loop of an Arduino sketch. The "loop" function is where the program's core functionality and tasks are implemented, and it runs repeatedly as long as the Arduino is powered on. Here's a simplified representation.


    void loop()

      {

      if (digitalRead(13) == 1) {

        tone(5, 659.25, 200);

        delay(200);

        tone(5, 783.99, 200);

        delay(200);

        tone(5, 1318.51, 200);

        delay(200);

        tone(5, 1046.5, 200);

        delay(200);

        tone(5, 1174.66, 200);

        delay(200);

        tone(5, 1567.98, 200);

        delay(200);

       randomSeed(analogRead(A0));

       GameManager();

       }

       }


HERE IS A VIDEO FOR UR REFERENCE:




 




    

 


Comments