Go Down

Topic: Timer program (Read 5 times) previous topic - next topic

soul1974

Jun 16, 2011, 09:20 am Last Edit: Jun 16, 2011, 01:58 pm by soul1974 Reason: 1
Hi,
I am very new to ARDUINO and programing and got this project from the inter net and I am having problems getting the program to reset once the correct code is imputed and once the time limit has been reach.

Can anyone please help? I have sent numorus emails to the creators but with no luck. I have fixed alot but seem to be at a dead end.

Code: [Select]
[font=Verdana][font=Verdana]

/*Airsoft TIMER
Version 1.1Creators:
Chase Cooley&&&&&&&&&&&&
Joey Meyer*/

#include <Keypad.h>
#include <LiquidCrystal.h>
#include <Tone.h>
#define pound 14

Tone tone1;
int Scount = 0; // count seconds
int Mcount = 0; // count minutes
int Hcount = 0; // count hours
int Dcount = 0; // count daysint val = 0;
long secMillis = 0; // store last time for second
long interval = 1000; // interval for seconds
char password[4];
int currentLength = 0;
int i = 0;char entered[4];
int ledPin = 5; //red light
int ledPin2 = 6; //green light

LiquidCrystal lcd(7,8,10,11,12,13);

//Keypad
const byte ROWS = 3; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] =
{
{'1','2','3','4'},
{'5','6','7','8'},
{'*','9','0','#'}
};
byte rowPins[ROWS] = {2, 14, 15}; //connect to the row pinouts of the keypad {18, 2, 14, 16}
byte colPins[COLS] = {16, 17, 18, 19}; //connect to the column pinouts of the keypad {17, 19, 15}
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

//LCD setup
void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
pinMode(ledPin2, OUTPUT); // sets the digital pin as output
tone1.begin(9);//pin for speaker
lcd.begin(16, 2);
Serial.begin(9600);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Enter Code: ");
while (currentLength < 4)
{
lcd.setCursor(currentLength + 6, 1);
lcd.cursor();
char key = keypad.getKey();
key == NO_KEY;
if (key != NO_KEY)
{
lcd.print(key);
password[currentLength] = key;
currentLength++;
delay(200);
}}
if (currentLength == 4)
{
lcd.noCursor();
lcd.clear();
lcd.home();
lcd.print("You've Entered: ");
lcd.setCursor(6,1);
lcd.print(password[0]);
lcd.print(password[1]);
lcd.print(password[2]);
lcd.print(password[3]);
delay(2500);
lcd.clear();
currentLength = 0;
}}

void loop()
{
char key2 = keypad.getKey(); // get the key
lcd.setCursor(0,0);
timer();
if (key2 != NO_KEY)
{
 while (key2 == NO_KEY)
{
 key2 = keypad.getKey();
}
if (key2 != NO_KEY)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Enter Code: ");
while (currentLength < 4)
{
lcd.setCursor(currentLength + 6, 1);
lcd.cursor();
char key2 = keypad.getKey();
if (key2 != NO_KEY)
{
lcd.print(key2);
entered[currentLength] = key2;
currentLength++;
delay(200);
lcd.noCursor();
lcd.setCursor(currentLength + 5, 1);
lcd.print("*");
lcd.setCursor(currentLength + 6, 1);
lcd.cursor();
}}
if (currentLength == 4)
{
if (entered[0] == password[0] && entered[1] == password[1] && entered[2] == password[2] && entered[3] == password[3])
{
lcd.noCursor();
lcd.clear();
lcd.home();
lcd.print(" Defused ");
currentLength = 0;
delay(2500);//sets the delay for defuse screen
lcd.setCursor(0,1);
lcd.print("Reset the Bomb");
}
else
{
lcd.noCursor();
lcd.clear();
lcd.home();
lcd.print(" Wrong ");
lcd.setCursor(0,1);
lcd.print(" Add - 0.30"); //LCD Display time added
if (Mcount < 5)
{
Mcount = Mcount + 0;
}
if (Scount < 59)
{
Scount = Scount + 30;
}
delay(1500);
currentLength = 0;
}
}}
}}

void timer()
{
if ( Mcount >= 5 )
while ( Mcount >= 5)
{
lcd.noCursor();lcd.clear();
lcd.home();
lcd.print(" !BoOo0o0o0om! ");
tone1.play(NOTE_A2, 200);
digitalWrite(ledPin, HIGH); // sets the LED on
tone1.play(NOTE_A2, 200);
delay(10); // waits for a second
digitalWrite(ledPin, LOW); // sets the LED off
tone1.play(NOTE_A2, 200);
delay(10); // waits for a second
digitalWrite(ledPin2, HIGH); // sets the LED on
tone1.play(NOTE_A2, 200);
delay(10); // waits for a second
digitalWrite(ledPin2, LOW); // sets the LED off
tone1.play(NOTE_A2, 200);
delay(10); // waits for a second
char key4 = keypad.getKey();
if (key4 != NO_KEY)
{
while (key4 == NO_KEY)
{
key4 = keypad.getKey();
}
if (key4 = '#')
{
lcd.clear();
lcd.print("Reset the Bomb");
}}
}
if ( Mcount == 60) // if Mcount is 60 do this operation
{
//delay (32); // good place to fine tune timing
Mcount = 0; // reset Mcount
Hcount ++;
}
if (Hcount> 23)
{
Dcount++;
Hcount = 0; // have to reset Hcount to "0" after 24hrs
}

lcd.setCursor (0,1); // sets cursor to 2nd line
lcd.print ("Timer: ");
lcd.print (Dcount);lcd.print (":");
lcd.print (Hcount);lcd.print (":");
lcd.print (Mcount);lcd.print (":");
lcd.print (Scount);
if (Scount >59) // if 60 do this operation
{
Mcount ++; // add 1 to Mcount
Scount = 0; // reset Scount
//delay (58); // changes ms per min
}
if (Scount < 60) // do this oper. 59 times
{
unsigned long currentMillis = millis();//delay (988); // changing by one = 60 ms a min
if(currentMillis - secMillis > interval)
{
tone1.play(NOTE_G5, 200);
secMillis = currentMillis;
Scount ++; // add 1 to Scount
digitalWrite(ledPin2, HIGH); // sets the LED on
delay(10); // waits for a second
digitalWrite(ledPin2, LOW); // sets the LED off
delay(10); // waits for a second
}
}}

[/font] [/font]

AWOL

#1
Jun 16, 2011, 09:23 am Last Edit: Jun 16, 2011, 09:37 am by AWOL Reason: 1
You've got some crazy indentation in that code.

Can you please go back to your post, click on "modify" (up on the right of your post), then highlight all the code, then click on a the "#" icon on the toolbar, then click "save".

Thanks.

What do you expect this code to do?
Code: [Select]
char key = keypad.getKey();
   key == NO_KEY;
   if (key != NO_KEY)


Strange construct:
Code: [Select]
  if (key2 != NO_KEY)
  {
    while (key2 == NO_KEY)
    {
      key2 = keypad.getKey();
    }
    if (key2 != NO_KEY)
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Nick Gammon

Code: [Select]
void timer()
{
  if ( Mcount >= 5 )
    while ( Mcount >= 5)
    {


You hardly need the "if" because the "while" will only do something if Mcount >= 5.
http://www.gammon.com.au/electronics

soul1974

Hi,

Like I stated before that this is code that I got from Instructables not mine .

Please could you help me ? I was told this is the forum to ask for help . =(

FalconFour

Actually you said you got it from the "inter net" (?) and that you "fixed a lot of it" (??), so who knows what was "fixed" (but it sure wasn't the formatting!)...

I should be asleep right now but this topic just screamed out for someone to help it along with some formatting. Nothing irks me more than poorly formatted code. A quick trip through Eclipse's one and only useful function - "Format" - and we get some readable code...

Code: [Select]
/*Airsoft TIMER
Version 1.1Creators:
Chase Cooley&&&&&&&&&&&&
Joey Meyer*/

#include <Keypad.h>
#include <LiquidCrystal.h>
#include <Tone.h>
#define pound 14

Tone tone1;
int Scount = 0; // count seconds
int Mcount = 0; // count minutes
int Hcount = 0; // count hours
int Dcount = 0; // count daysint val = 0;
long secMillis = 0; // store last time for second
long interval = 1000; // interval for seconds
char password[4];
int currentLength = 0;
int i = 0;
char entered[4];
int ledPin = 5; //red light
int ledPin2 = 6; //green light

LiquidCrystal lcd(7, 8, 10, 11, 12, 13);

//Keypad
const byte ROWS = 3; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = { { '1', '2', '3', '4' }, { '5', '6', '7', '8' }, {
'*', '9', '0', '#' } };
byte rowPins[ROWS] = { 2, 14, 15 }; //connect to the row pinouts of the keypad {18, 2, 14, 16}
byte colPins[COLS] = { 16, 17, 18, 19 }; //connect to the column pinouts of the keypad {17, 19, 15}
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

//LCD setup
void setup() {
pinMode(ledPin, OUTPUT); // sets the digital pin as output
pinMode(ledPin2, OUTPUT); // sets the digital pin as output
tone1.begin(9);//pin for speaker
lcd.begin(16, 2);
Serial.begin(9600);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter Code: ");
while (currentLength < 4) {
lcd.setCursor(currentLength + 6, 1);
lcd.cursor();
char key = keypad.getKey();
key == NO_KEY;
if (key != NO_KEY) {
lcd.print(key);
password[currentLength] = key;
currentLength++;
delay(200);
}
}
if (currentLength == 4) {
lcd.noCursor();
lcd.clear();
lcd.home();
lcd.print("You've Entered: ");
lcd.setCursor(6, 1);
lcd.print(password[0]);
lcd.print(password[1]);
lcd.print(password[2]);
lcd.print(password[3]);
delay(2500);
lcd.clear();
currentLength = 0;
}
}

void loop() {
char key2 = keypad.getKey(); // get the key
lcd.setCursor(0, 0);
timer();
if (key2 != NO_KEY) {
while (key2 == NO_KEY) {
key2 = keypad.getKey();
}
if (key2 != NO_KEY) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter Code: ");
while (currentLength < 4) {
lcd.setCursor(currentLength + 6, 1);
lcd.cursor();
char key2 = keypad.getKey();
if (key2 != NO_KEY) {
lcd.print(key2);
entered[currentLength] = key2;
currentLength++;
delay(200);
lcd.noCursor();
lcd.setCursor(currentLength + 5, 1);
lcd.print("*");
lcd.setCursor(currentLength + 6, 1);
lcd.cursor();
}
}
if (currentLength == 4) {
if (entered[0] == password[0] && entered[1] == password[1]
&& entered[2] == password[2] && entered[3]
== password[3]) {
lcd.noCursor();
lcd.clear();
lcd.home();
lcd.print(" Defused ");
currentLength = 0;
delay(2500);//sets the delay for defuse screen
lcd.setCursor(0, 1);
lcd.print("Reset the Bomb");
} else {
lcd.noCursor();
lcd.clear();
lcd.home();
lcd.print(" Wrong ");
lcd.setCursor(0, 1);
lcd.print(" Add - 0.30"); //LCD Display time added
if (Mcount < 5) {
Mcount = Mcount + 0;
}
if (Scount < 59) {
Scount = Scount + 30;
}
delay(1500);
currentLength = 0;
}
}
}
}
}

void timer() {
if (Mcount >= 5)
while (Mcount >= 5) {
lcd.noCursor();
lcd.clear();
lcd.home();
lcd.print(" !BoOo0o0o0om! ");
tone1.play(NOTE_A2, 200);
digitalWrite(ledPin, HIGH); // sets the LED on
tone1.play(NOTE_A2, 200);
delay(10); // waits for a second
digitalWrite(ledPin, LOW); // sets the LED off
tone1.play(NOTE_A2, 200);
delay(10); // waits for a second
digitalWrite(ledPin2, HIGH); // sets the LED on
tone1.play(NOTE_A2, 200);
delay(10); // waits for a second
digitalWrite(ledPin2, LOW); // sets the LED off
tone1.play(NOTE_A2, 200);
delay(10); // waits for a second
char key4 = keypad.getKey();
if (key4 != NO_KEY) {
while (key4 == NO_KEY) {
key4 = keypad.getKey();
}
if (key4 = '#') {
lcd.clear();
lcd.print("Reset the Bomb");
}
}
}
if (Mcount == 60) // if Mcount is 60 do this operation
{
//delay (32); // good place to fine tune timing
Mcount = 0; // reset Mcount
Hcount++;
}
if (Hcount > 23) {
Dcount++;
Hcount = 0; // have to reset Hcount to "0" after 24hrs
}

lcd.setCursor(0, 1); // sets cursor to 2nd line
lcd.print("Timer: ");
lcd.print(Dcount);
lcd.print(":");
lcd.print(Hcount);
lcd.print(":");
lcd.print(Mcount);
lcd.print(":");
lcd.print(Scount);
if (Scount > 59) // if 60 do this operation
{
Mcount++; // add 1 to Mcount
Scount = 0; // reset Scount
//delay (58); // changes ms per min
}
if (Scount < 60) // do this oper. 59 times
{
unsigned long currentMillis = millis();//delay (988); // changing by one = 60 ms a min
if (currentMillis - secMillis > interval) {
tone1.play(NOTE_G5, 200);
secMillis = currentMillis;
Scount++; // add 1 to Scount
digitalWrite(ledPin2, HIGH); // sets the LED on
delay(10); // waits for a second
digitalWrite(ledPin2, LOW); // sets the LED off
delay(10); // waits for a second
}
}
}


Have at, guys! There's a lot of work to do... especially "delay(10); // waits for a second" (you mean, waits 1/10th a second? haha).

soul1974

Hi,
Sry for the confusion, this is the origanal code posted on Instructables. I have never done coding before but will definatley use your code as a stepping stone.

Thanks for the help and sry for keeping you up.

Code: [Select]


/*Airsoft Bomb
Version 1.1Creators:
Chase Cooley&&&&&&&&&&&&
Joey Meyer*/
#include <Keypad.h>#include <LiquidCrystal.h>
#include <Tone.h>
#define pound 14
Tone tone1;int Scount = 0; // count seconds
int Mcount = 0; // count minutesint Hcount =0; // count hours
int Dcount = 0; // count daysint val = 0;
long secMillis = 0; // store last time for second addlong interval = 1000; // interval for seconds
char password[4];int currentLength = 0;
int i = 0;char entered[4];
int ledPin = 3; //red lightint ledPin2 = 4; //green light
LiquidCrystal lcd(7,8,10,11,12,13);const byte ROWS = 4; //four rows
const byte COLS = 3; //three columnschar keys[ROWS][COLS] = {
{'1','2','3'},{'4','5','6'},
{'7','8','9'},{'*','0','#'}
};
byte rowPins[ROWS] = {18, 2, 14, 16}; //connect to the row pinouts of the keypadbyte colPins[COLS] = {17, 19, 15}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
pinMode(ledPin, OUTPUT); // sets the digital pin as outputpinMode(ledPin2, OUTPUT); // sets the digital pin as output
tone1.begin(9);lcd.begin(16, 2);
Serial.begin(9600);lcd.clear();
lcd.setCursor(0,0);lcd.print("Enter Code: ");
while (currentLength < 4){
lcd.setCursor(currentLength + 6, 1);lcd.cursor();
char key = keypad.getKey();key == NO_KEY;
if (key != NO_KEY){
lcd.print(key);password[currentLength] = key;
currentLength++;delay(200);
}}
if (currentLength == 4){
lcd.noCursor();lcd.clear();
lcd.home();lcd.print("You've Entered: ");
lcd.setCursor(6,1);lcd.print(password[0]);
lcd.print(password[1]);lcd.print(password[2]);
lcd.print(password[3]);delay(3000);
lcd.clear();currentLength = 0;
}}
void loop(){
char key2 = keypad.getKey(); // get the keylcd.setCursor(0,0);
timer();if (key2 != NO_KEY)
{while (key2 == NO_KEY)
{key2 = keypad.getKey();
}if (key2 != NO_KEY)
{lcd.clear();
lcd.setCursor(0,0);lcd.print("Enter Code: ");
while (currentLength < 4){
lcd.setCursor(currentLength + 6, 1);lcd.cursor();
char key2 = keypad.getKey();if (key2 != NO_KEY)
{lcd.print(key2);
entered[currentLength] = key2;currentLength++;
delay(200);lcd.noCursor();
lcd.setCursor(currentLength + 5, 1);lcd.print("*");
lcd.setCursor(currentLength + 6, 1);lcd.cursor();
}}
if (currentLength == 4){
if (entered[0] == password[0] && entered[1] == password[1] && entered[2] == password[2] && entered[3] == password[3]){
lcd.noCursor();lcd.clear();
lcd.home();lcd.print(" Defused ");
currentLength = 0;delay(2500);
lcd.setCursor(0,1);lcd.print("Reset the Bomb");
}else
{lcd.noCursor();
lcd.clear();lcd.home();
lcd.print(" Wrong ");lcd.setCursor(0,1);
lcd.print(" Add - 1:30 ");if (Mcount < 14)
{Mcount = Mcount + 1;
}if (Scount < 59)
{Scount = Scount + 30;
}delay(1500);
currentLength = 0;}
}}
}}

AWOL

That's even less legible - what did you do to it?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Fletcher Chr

Quote
Have at, guys! There's a lot of work to do... especially "delay(10); // waits for a second" (you mean, waits 1/10th a second? haha).


... or maybe even waite 1/100th of a second  ]:)

-Fletcher

soul1974

That is how they posted on the site, http://www.instructables.com/id/Prop-bomb/. I have request them to help but no joy.

AWOL

Ah! Another quality posting from Instructables.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Nick Gammon


Hi,
Sry for the confusion, this is the origanal code posted on Instructables. I have never done coding before but will definatley use your code as a stepping stone.


That doesn't even compile, nor does auto-format work - too many curly braces.


I am very new to ARDUINO and programing and got this project from the inter net and I am having problems getting the program to reset once the correct code is imputed and once the time limit has been reach.

Can anyone please help? I have sent numorus emails to the creators but with no luck. I have fixed alot but seem to be at a dead end.


Let's go back to basics here. What are you trying to do? What is your circuit? What "correct code"? What "time limit"? What do you mean "I am having problems getting the program to reset"? You can hit the "reset" button. It isn't at all clear what you have, what it does, what you want it to do, and in what way what it does differs from what you want it to do.
http://www.gammon.com.au/electronics

FalconFour

Alright, it's pretty clear the poor guy really has no idea what's going on. But in the good ole' Arduino spirit of helpfulness, I think we should quit being so hard on the guy... I think he's just trying to get something done, obviously didn't write the code, and just wants a little help getting this "mystery blob of code" to work right...

To that effect, that's why I used Eclipse to reformat the botched garble of code into something readable:

>> http://arduino.cc/forum/index.php/topic,64119.msg466921.html#msg466921 <<
---- LOOK HERE FOR THE CODE, DANGIT! ----
(for those scroll-skimmers)

With that out of the way, I'll take a whack at re-interpreting the code here in a few minutes, I've got a few to burn...

FalconFour

#12
Jun 17, 2011, 12:20 am Last Edit: Jun 17, 2011, 08:14 am by FalconFour Reason: 1
Alright, here you go, have a ball.

I went through it line by line, removed an obscene number of useless statements (like lcd.home() and lcd.setCursor(0,0) after a lcd.clear()... or a "if key == key" after a "while (key != key)" statement... ugh!), and did my best to interpret the way it's supposed to work... I don't even have an Arduino board handy here at my office, but I figure this will work fine as long as you provide that "keypad.h" file it's asking for (I didn't bother searching for it... I'm guessing you have it?).

Code: [Select]
/*Airsoft TIMER
Version 1.5
Creators:
Chase Cooley
Joey Meyer
Turned into usable code, 6/16/2011:
Matt Falcon*/

#include <Keypad.h>
#include <LiquidCrystal.h>
#define pound 14
#define LED_RED 5
#define LED_GREEN 6
#define KP_ROWS 3
#define KP_COLS 4

unsigned int timerSeconds = 300; // start with 5 minutes on the clock
byte password[4];
byte entered[4];
int currentLength = 0;
byte i = 0;

LiquidCrystal lcd(7, 8, 10, 11, 12, 13);

//Keypad
char keys[KP_ROWS][KP_COLS] = { { '1', '2', '3', '4' }, { '5', '6', '7', '8' }, {
'*', '9', '0', '#' } };
byte rowPins[KP_ROWS] = { 2, 14, 15 }; //connect to the row pinouts of the keypad {18, 2, 14, 16}
byte colPins[KP_COLS] = { 16, 17, 18, 19 }; //connect to the column pinouts of the keypad {17, 19, 15}
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, KP_ROWS, KP_COLS);

char key;

//LCD setup
void setup() {
pinMode(LED_RED, OUTPUT); // sets the digital pin as output
pinMode(LED_GREEN, OUTPUT); // sets the digital pin as output
lcd.begin(16, 2);
lcd.print("Enter Code: ");
lcd.cursor();
lcd.setCursor(6, 1);
while (currentLength < 4) {
key = keypad.getKey();
if (key != NO_KEY) {
lcd.print(key);
password[currentLength] = key;
currentLength++;
lcd.setCursor(currentLength + 6, 1);
} else delay(100); // only sample it every 1/10 sec, no need to go apesh!t
}
lcd.noCursor();
lcd.clear();
lcd.print("You've Entered: ");
lcd.setCursor(6, 1);
lcd.print(password[0],DEC);
lcd.print(password[1],DEC);
lcd.print(password[2],DEC);
lcd.print(password[3],DEC);
delay(2500);
lcd.clear();
currentLength = 0;
}

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("*");
lcd.setCursor(currentLength + 6, 1);
lcd.print(key);
entered[currentLength] = key;
currentLength++;
} else delay(100); // only sample it every 1/10 sec
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 ");
lcd.setCursor(0, 1);
lcd.print("Reset the Bomb");
delay(2500); // hold that on screen for 2.5 seconds
currentLength = 0;
} else {
lcd.noCursor();
lcd.clear();
lcd.print(" Wrong ");
lcd.setCursor(0, 1);
lcd.print(" Time -0:30"); // Display time penalty
if (timerSeconds > 30) timerSeconds -= 30;
else timerSeconds = 1; // will trigger BOOM next cycle
currentLength = 0;
delay(2500); // hold that on screen for 2.5 seconds
}
}
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_GREEN,!digitalRead(LED_GREEN)); // toggle the green LED once a second
tone(9,784, 200); // play bleep for 50ms
delay(50); // and there's the rest of that 1 second (not counting LCD delay)

timerSeconds--;
if (timerSeconds == 0) bombomb();
}
void bombomb() {
// routine for making ze BOMB GOEZ OFF!!!1 :D
lcd.noCursor();
lcd.clear();
lcd.print(" !BoOo0o0o0om! ");
tone(9,110, 200);
digitalWrite(LED_RED, HIGH); // sets the red LED on
delay(500); // waits half a second
tone(9,110, 200);
delay(500); // waits half a second
digitalWrite(LED_RED, LOW); // sets the red LED off
digitalWrite(LED_GREEN, HIGH); // sets the green LED on
tone(9,110, 200);
delay(500); // waits half a second
digitalWrite(LED_RED, HIGH); // sets the red LED on
digitalWrite(LED_GREEN, LOW); // sets the green LED off
tone(9,110, 200);
delay(500); // waits half a second
digitalWrite(LED_RED, LOW); // sets the red LED off
digitalWrite(LED_GREEN, HIGH); // sets the green LED on
tone(9,110, 200);
delay(500); // waits half a second
digitalWrite(LED_GREEN, LOW); // sets the green LED off
key = NO_KEY; // enter the while() loop, otherwise it'll skip. i could use do { } while();, but I'm lazy.
while (key == NO_KEY) {
key = keypad.getKey();
if (key == '#') {
lcd.clear();
lcd.print("Reset the Bomb");
delay(2500); // good ole' 2.5 sec delay
timerSeconds = 300; // put 5 minutes on the clock
// and we break the loop and go back to timer.
} else key = NO_KEY; // continue looking for pound key
}
}


Let me know how it works... I literally haven't even tested this! Of course, last time I posted code that "I haven't even tested", I got grilled for it, but whatever... it's better than what the rest of the users here are contributing ;)

edit: Almost forgot... oughtta tack my name into the header =P
edit: declared "key" globally since we use it so often in the program...

soul1974

Thank you for taking the time to help a noob.

the code give me this  error.

Code: [Select]
sketch_jun17a.cpp: In function 'void bombomb()':
sketch_jun17a:144: error: 'key' was not declared in this scope

soul1974

Hi,

The code is for a airsoft E-bomb, it is mounted in a briefcase and is carried by the players to a set destination on the playing field. once they have reached thier destination they activate the E-bomb with a code they have choosen and defend it for 5 minutes ,if they succeed in defending it it with sound a siren .If the opposing team reach the E-bomb they must disarm it by choosing a from a list of codes if they choose wron it adds
time to the clock , if they succed in getting the right code then the E-bomb is defused and they win.



Hi,
Sry for the confusion, this is the origanal code posted on Instructables. I have never done coding before but will definatley use your code as a stepping stone.


That doesn't even compile, nor does auto-format work - too many curly braces.


I am very new to ARDUINO and programing and got this project from the inter net and I am having problems getting the program to reset once the correct code is imputed and once the time limit has been reach.

Can anyone please help? I have sent numorus emails to the creators but with no luck. I have fixed alot but seem to be at a dead end.


Let's go back to basics here. What are you trying to do? What is your circuit? What "correct code"? What "time limit"? What do you mean "I am having problems getting the program to reset"? You can hit the "reset" button. It isn't at all clear what you have, what it does, what you want it to do, and in what way what it does differs from what you want it to do.

Go Up