Hi iim trying to make a fake csgo Bomb planting and defusing code and i added the code to make the double beeping sound with this code :
int i=0;
while (i < 20)
{
tone(buzzerPin, NOTE_G5, 100);
delay(100);
tone(buzzerPin, NOTE_G5, 100);
i++;
delay(800);
}
and i dont know where to put it i tried many places but all of them got stuck in the place i put it like when i put in here :
if (enteredCode > 0) {
armingCode = enteredCode;
lcd.clear();
lcd.print("Bomb is planted!");
bombPlanted = true;
}
i was just stuck in this code for 20 beeps and then it went to the next section
here is my code :
#include <LiquidCrystal.h>
#include <Keypad.h>
#include <pitches.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {A0, A1, A2, A3};
byte colPins[COLS] = {A4, A5, A6, A7};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
const int buzzerPin = 8;
int armingCode = 9023;
int defuseCode = 1290;
bool bombPlanted = false;
bool isBeeping = false;
unsigned long lastBeepTime = 0;
void setup() {
lcd.begin(16, 2);
pinMode(buzzerPin, OUTPUT);
lcd.print("Welcome to CS:Arduino");
delay(2000);
lcd.clear();
}
void loop() {
if (!bombPlanted) {
lcd.setCursor(0, 0);
lcd.print("Enter planting code:");
int enteredCode = 0;
int position = 0;
while (position < 4) {
char key = keypad.getKey();
if (key) {
lcd.setCursor(position, 1);
lcd.print('*');
enteredCode = enteredCode * 10 + (key - '0');
position++;
}
}
if (enteredCode > 0) {
armingCode = enteredCode;
lcd.clear();
lcd.print("Bomb is planted!");
bombPlanted = true;
}
} else {
lcd.clear();
lcd.print("Invalid code!");
delay(2000);
lcd.clear();
}
} else {
lcd.setCursor(0, 0);
lcd.print("Enter defuse code:");
int enteredCode = 0;
int position = 0;
while (position < 4) {
char key = keypad.getKey();
if (key) {
lcd.setCursor(position, 1);
lcd.print('*');
enteredCode = enteredCode * 10 + (key - '0');
position++;
tone(buzzerPin, NOTE_E3, 100);
}
}
if (enteredCode == armingCode) {
lcd.clear();
lcd.print("Bomb defused!");
noTone(buzzerPin);
bombPlanted = false;
delay(2000);
lcd.clear();
tone(buzzerPin, NOTE_E3, 100);
delay(100);
tone(buzzerPin, NOTE_E3, 100);
} else {
lcd.clear();
lcd.print("Wrong code!");
delay(1000);
lcd.clear();
}
}
}
