Hi all,
This Arduino stuff is great and as poke my interest after reading a lot of stuff that people as done with, one of them is a fellow in Australia who as done some coding for flightsim. I'm working on this for my cockpit stuff.
My son is in paintball and airsoft stuff and I came across this code for the airbomb. I know this is an old code but I just need a little help to add or fix part of the code as I'm also a newbie.
I got the code to work the way I want and with the hardware that I have, screen, lights, sound and keypad.
Only flaw that I cant seem to be able to fix is when the timer is counting down and I press a key the timer stop and if I only press 1 to 3 keys it stays like that forever until I press 4 keys, then it will show either it is wrong or defused the way it is supposed to.
In a game this is not good as one only have to push a key and the bomb is frozen in time.
The timer should either keep on going or if no inputs is keyed in a set of time like (4 or 5 sec) then the timer should resume automatically.
In the code it mention about pause the timer effectively I think it's too effective!! lol
Anyway here is what I got as far as code goes (REMEMBER I'M ONLY A NEWBIE) lol
The full file is attached.
void loop() {
** lcd.clear();**
** lcd.print("Enter Code: ");**
** lcd.cursor();**
** key = keypad.getKey(); // get the key once per this loop**
** if (key != NO_KEY) {**
** lcd.setCursor(0, 1);**
** lcd.print(" ");**
** lcd.setCursor(6, 1);**
** while (currentLength < 4) {**
** // here, we take the key that broke us into this "if" statement, instead of discarding it. this also pauses the timer, effectively.**
** if (key != NO_KEY)**
** { // redundant for the first loop, but necessary for every next character**
** lcd.setCursor(currentLength + 5, 1);**
** lcd.print(key);**
** entered[currentLength] = key;**
** currentLength++;**
** }**
** else delay(10);**
** key = keypad.getKey(); // get the key every time "while" loops**
** }**
if (memcmp(entered,password,4) == 0) { // shortcut to compare an array of bytes, use memcmp(A, B, length), will return 0 if match.
lcd.noCursor();
lcd.clear();
lcd.print(" Defused ");
digitalWrite(LED_RED, HIGH); // sets the red LED on
digitalWrite(LED_GREEN, HIGH); // sets the green LED on
delay(4000);
tone(9,1200, 2000); //
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Bomb Rebooting");
lcd.setCursor(0,1 );
lcd.print("Have a nice day!");
currentLength = 0;
digitalWrite(LED_RED, LOW); // sets the red LED off
digitalWrite(LED_GREEN, LOW); // sets the green LED off
delay(4000); // hold that on screen for 2.5 seconds
lcd.clear();
currentLength = 0;
void (*softReset) (void) = 0; //declare reset function @ address 0
softReset();
setup();
}
else {
lcd.noCursor();
lcd.clear();
lcd.print(" Wrong ");
tone(9,110, 2500);
digitalWrite(LED_RED, HIGH); // sets the red LED on
digitalWrite(LED_GREEN, HIGH); // sets the green LED on
lcd.setCursor(0, 1);
lcd.print("Penalty -2:00"); // Display time penalty
if (timerSeconds > 120) timerSeconds -= 120;
else timerSeconds = 1; // will trigger BOOM next cycle
currentLength = 0;
delay(2500); // hold that on screen for 2.5 seconds
digitalWrite(LED_RED, LOW); // sets the red LED off
digitalWrite(LED_GREEN, LOW); // sets the green LED off
lcd.clear();
}
}
timer(); // prints current time on screen, checks for "go off" time, holds loop for 1 second
}
void timer() {
lcd.setCursor(0, 1); // sets cursor to 2nd line
lcd.print("Timer: ");
lcd.print(timerSeconds / 60); // integer number of minutes on clock
lcd.print(":");
lcd.print(timerSeconds % 60); // mod 60; gives us number of seconds outside of 60sec/min
delay(950); // hold us here for 0.950 seconds
{
digitalWrite(LED_RED,!digitalRead(LED_RED)); // toggle the red LED once a second
}
tone(9,800, 250); // play bleep for 50ms
delay(50); // and there's the rest of that 1 second (not counting LCD delay)
timerSeconds--;
if (timerSeconds == 0) bombomb();
}
AirBomb2.ino (11.4 KB)