Barqunics
Published © GPL3+

Minifigures Battle Game

The goal of the game is push opponent’s minifigure using stick so opponent’s led bar will drop by one.

IntermediateShowcase (no instructions)20 hours143

Things used in this project

Story

Read more

Schematics

minifigures_battle_game_BFJnBNuMZa.png

Code

Minifigures_Battle_Game.ino

Arduino
#include <Grove_LED_Bar.h>
#include <SPI.h>
#include <MFRC522.h>

#define SS_PIN 9
#define RST_PIN 7
#define SS_PIN2 10
#define RST_PIN2 8

MFRC522 firstMfrc522(SS_PIN, RST_PIN);         // Create  first MFRC522 instance.
MFRC522 secondMfrc522(SS_PIN2, RST_PIN2);      // Create  second MFRC522 instance.
Grove_LED_Bar firstBar(6, 5, 0, LED_BAR_10);   // Clock pin, Data pin, Orientation
Grove_LED_Bar secondBar(A0, A1, 0, LED_BAR_10);  // Clock pin, Data pin, Orientation

int ledIndex1 = 10;  // Start with LED 10
bool state1 = false;
int ledIndex2 = 10;  // Start with LED 10
bool state2 = false;

void setup() {
  Serial.begin(9600);
  firstBar.begin();
  secondBar.begin();
  SPI.begin();               // Initiate  SPI bus
  firstMfrc522.PCD_Init();   // Initiate firstMfrc522
  firstBar.setLevel(10);     // Turn on all LEDs
  secondMfrc522.PCD_Init();  // Initiate firstMfrc522
  secondBar.setLevel(10);    // Turn on all LEDs
  Serial.println("Approximate your card to the reader...");
  Serial.println();
}

void loop() {
  // For the first character
  if (firstMfrc522.PICC_IsNewCardPresent() && firstMfrc522.PICC_ReadCardSerial()) {

    Serial.print("UID tag :");
    String content = "";
    byte letter;
    for (byte i = 0; i < firstMfrc522.uid.size; i++) {
      Serial.print(firstMfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
      Serial.print(firstMfrc522.uid.uidByte[i], HEX);
      content.concat(String(firstMfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
      content.concat(String(firstMfrc522.uid.uidByte[i], HEX));
    }
    Serial.println();
    content.toUpperCase();
    if (content.substring(1) == "99 D6 AF A2") {  //change here the UID of the tag
      state1 = true;
      for (int i = 0; i <= ledIndex1; i++) {
        firstBar.setLevel(i);
        delay(100);
      }
    }
  } else if (!firstMfrc522.PICC_IsNewCardPresent() && !firstMfrc522.PICC_ReadCardSerial() && state1) {
    ledIndex1--;
    firstBar.setLevel(ledIndex1);
    state1 = false;
    delay(1000);
  }

  // For the second character
  if (secondMfrc522.PICC_IsNewCardPresent() && secondMfrc522.PICC_ReadCardSerial()) {

    Serial.print("UID tag :");
    String content = "";
    byte letter;
    for (byte i = 0; i < secondMfrc522.uid.size; i++) {
      Serial.print(secondMfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
      Serial.print(secondMfrc522.uid.uidByte[i], HEX);
      content.concat(String(secondMfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
      content.concat(String(secondMfrc522.uid.uidByte[i], HEX));
    }
    Serial.println();
    content.toUpperCase();
    if (content.substring(1) == "37 DB 9B 60") {   //change here the UID of the tag
      state2 = true;
      for (int i = 0; i <= ledIndex2; i++) {
        secondBar.setLevel(i);
        delay(100);
      }
    }
  } else if (!secondMfrc522.PICC_IsNewCardPresent() && !secondMfrc522.PICC_ReadCardSerial() && state2) {
    ledIndex2--;
    secondBar.setLevel(ledIndex2);
    state2 = false;
    delay(1000);
  }
}

Credits

Barqunics

Barqunics

7 projects • 71 followers
Hello, My name is Ikhsan

Comments