Go Down

Topic: BOMB CODE then Timer URGENT (Read 433 times) previous topic - next topic

kdawk

HI guys I'm trying to make a prob bomb game. It should start with a keypad password. after the right password then there is a timer that counts down while you play a jumper wire game. which act as just buttons i guess. For the life of me I can't get it figured. I require URGENT help. PLEASE HELP !

CODE:

#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

#define Password_Length 9

int seconds = 15; // count seconds
int minutes = 1; // count minutes
int hours = 0; // count hours

char Data[Password_Length];
char Master[Password_Length] = "20134030";
byte data_count = 0, master_count = 0;
bool Pass_is_good;
char customKey;

const byte ROWS = 4;
const byte COLS = 4;

char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

byte rowPins[ROWS] = {3, 4, 5, 6};
byte colPins[COLS] = {7, 8, 9};

Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

LiquidCrystal_I2C lcd(0x3F, 20, 4);

void setup()
{
  lcd.init();                      // initialize the lcd
  lcd.init();
  // Print a message to the LCD.
  lcd.backlight();
  lcd.begin(20, 4); //set up the LCD's number of columns and rows
  // declare pin 9 to be an output:

  digitalWrite(23, HIGH);
  pinMode(14, INPUT_PULLUP);
  pinMode(15, INPUT_PULLUP);
  pinMode(16, INPUT_PULLUP);
  pinMode(17, INPUT_PULLUP);
  pinMode(18, INPUT_PULLUP);
  pinMode(A0, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
  pinMode(A1, OUTPUT);
}
void clearData() {
  while (data_count != 0) {
    Data[data_count--] = 0;
  }
}
void stepDown() {
  if (seconds > 0) {
    seconds -= 1;
  } else {
    if (minutes > 0) {
      seconds = 59;
      minutes -= 1;
    } else {


    }
  }
}
void Socket()
{
  if (digitalRead(14) == LOW)
  {
    digitalWrite(A0, HIGH);

  }

  else
  {
    digitalWrite(A0, LOW);

  }
  if (digitalRead(15) == LOW)
  {
    digitalWrite(10, HIGH);
  }
  else
  {
    digitalWrite(10, LOW);
  }

  if (digitalRead(16) == LOW )
  {
    digitalWrite(12, HIGH);
  }
  else
  {
    digitalWrite(12, LOW);
  }
  if ( digitalRead(17) == LOW)
  {
    digitalWrite(11, HIGH);
  }
  else
  {
    digitalWrite(11, LOW);
  }

  if (digitalRead(18) == LOW && digitalRead(17) == LOW && digitalRead(16) == LOW &&
      digitalRead(14) == LOW && digitalRead(15) == LOW)
  {
    digitalWrite(A1, HIGH);
    digitalWrite(13, HIGH);
    lcd.noDisplay();
    delay(7000);
  }

  else
  {
    digitalWrite(A1, HIGH);
    digitalWrite(13, HIGH);
  }
  digitalWrite(2, HIGH);
}


void Timer() {
  // put your main code here, to run repeatedly:
  lcd.begin(20, 4);
  lcd.print("DETONATION IN: ");

  // lcd.scrollDisplayLeft();
  // wait a bit:
  delay(2000);

  while (minutes > 0 || seconds > 0) {

    lcd.setCursor(4, 2);

    (minutes < 10) ? lcd.print("0") : NULL;
    lcd.print(minutes);
    lcd.print(":");
    (seconds < 10) ? lcd.print("0") : NULL;
    lcd.print(seconds);
    lcd.display();
    stepDown();
    delay(1000);

  }
  if (digitalRead(18) == LOW && digitalRead(17) == LOW && digitalRead(16) == LOW &&
      digitalRead(14) == LOW && digitalRead(15) == LOW)
  {
    digitalWrite(A1, HIGH);
    digitalWrite(13, HIGH);
    lcd.noDisplay();
    delay(7000);
  }
  while (minutes == 0 && seconds == 0)
  { lcd.clear();
    lcd.print("   BOMB DETONATED");
    delay(1500);
  }
}


void loop() {
  lcd.setCursor(0, 0);
  lcd.print("Enter Password:");

  customKey = customKeypad.getKey();
  if (customKey == '*')
  { lcd.clear();
    clearData();
    lcd.setCursor(0, 1);
  }
  if (customKey >= '0' && customKey <= '9') {
    Data[data_count] = customKey;
    lcd.setCursor(data_count, 1);
    lcd.print(Data[data_count]);
    data_count++;

  }

  if (data_count == Password_Length - 1) {
    lcd.clear();

    if (!strcmp(Data, Master)) {
      Timer();

    }

    else {

      lcd.print("Incorrect");
      delay(1500);


    }

    lcd.clear();
    clearData();
  }


}

Help Me out please

Excuse me. I know your message was urgent, but I only saw it today, searching for the Arduino Due.
There is at least one bug in your code. You are using a 4x4 Keypad, but at the time of creating the Array for the columns, you used only 3 pins.


Code: [Select]

const byte ROWS = 4;
const byte COLS = 4;

char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

byte rowPins[ROWS] = {3, 4, 5, 6};
byte colPins[COLS] = {7, 8, 9}; //// <<<<<< This is what I am talking about.... You need one more pin.


have you seen this here:
https://nootropicdesign.com/gametimerpro/

Or this:
https://www.instructables.com/id/Arduino-defuseable-bomb-perfect-for-airsoft-games-/

I hope it helps.

Go Up