Timer / count down thing

Hi
I need a push going down the rigth road :slight_smile:
(sry for my bad english)

I have a keypad, where i need to push etc. 5 min. then after the 5 min. a led1 go high. But if I push the right code in the timer stops and led2 go high

I hope someone can help me :slight_smile:

Do you show us your code?

Hi
sry :slight_smile: have marked it with ****
I dont have any idea how to do it

/*  Keypadtest.pde
 *
 *  Demonstrate the simplest use of the  keypad library.
 *
 *  The first step is to connect your keypad to the
 *  Arduino  using the pin numbers listed below in
 *  rowPins[] and colPins[]. If you want to use different
 *  pins then  you  can  change  the  numbers below to
 *  match your setup.
 *
 */
#include <Keypad.h>
#include <Password.h>
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);


char kode[5];
char start[5] = {'1','2','3','4','5'};
char slut[5] = {'0','0','0','0','0'};
int i = 0;
int f = 0;
int t = 0;
char time[5];
char tid[5];
int a = 5;


//Password password = Password( "9999" );
//Password admin = Password( "0000" );
//Password bruger1 = Password( "1111" );
//Password bruger2 = Password( "2222" );
 
const byte ROWS = 4; // Four rows
const byte COLS = 3; // Three columns
// Define the Keymap
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 10, 9, 8, 14 };
// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 13, 12, 11 }; 

// Create the Keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup()
{
  Serial.begin(9600);
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  
}

void loop(){
  char key = kpd.getKey();

if(t == 1)         //Hvis admin pass er trykket og godkendt
  {

******* the time that is entered is counting down, But if you enter the rigth code (00000)
it stops and go to checkPassword() *****
              
   }

 if (t == 0)        //Starten af programmet - nulstillet.
 {
  lcd.setCursor(0, 0); 
  lcd.print("Tast Start kode");
  }
 else              //Hvis Der er tastet admin kode.
 {
  lcd.setCursor(2, 0); 
  lcd.print("Tast Kodeord");
 }


  if(key && t != 2 && f != 3)    // Hvis der trykkes på kaypaddet og bomben er "armed"
  {

    
    kode[i] = key; //store entry into array
    i++;
    Serial.println(key); //print keypad character entry to serial port
    
    lcd.setCursor(a + i, 1);
    lcd.print(key);
    Serial.println(a , i);
    
    
    if (key=='*')
    {
	Serial.println("Reset");
	i=0; //reset i
        a=5;
        lcd.clear();
    }

    if (i == 5) //if 4 presses have been made
    {
	checkPassword();

	{
	 i=0;
         a=5;
         lcd.clear();
	}
    }
   }
   if ( f == 3 || t == 2 )          // Hvis der forsøges mere end 3 gange eller tiden er gået.
   {
     Serial.println( "booom");
     lcd.clear();
     lcd.setCursor(3, 0);
     lcd.print("BOOOOOOOOM");
     f = 0;
     t = 0;
     delay (10000);
     Serial.println( "igen");
     lcd.clear();
    
   }
   
     
  
}

void checkPassword(){
  

  i=0;
 if ( t == 0 && kode[0] == start[0] &&      // tjekker admin kode og staret programmet i "armed"
      kode[1] == start[1] &&
      kode[2] == start[2] &&
      kode[3] == start[3] &&
      kode[4] == start[4] )
      {
        Serial.println("Start");
        t = 1;
        f = 0;
        lcd.clear();

******* press the time.. finish with #  *****

            
        lcd.print("     Armed");
        delay(2000);
        lcd.clear();
      }
      
      
 else if (t == 1 && kode[0] == slut[0] &&
      kode[1] == slut[1] &&
      kode[2] == slut[2] &&
      kode[3] == slut[3] &&
      kode[4] == slut[4] )
      {
        Serial.println("STOP");
        t = 0;
        f = 0;
       lcd.clear();
       lcd.print("    Disarmed");
       delay(1500);
       lcd.clear();
       }
 else
 {
   if ( t == 1 )            // Hvis programmet er startet og koden er forkert.
   {
   Serial.println("Forkert");
   f++;
   lcd.clear();
   lcd.print("Forkert kode");
   lcd.setCursor(0,1);
   delay(1000);
   lcd.clear();
   lcd.print("Forsøg Tilbage");
   lcd.setCursor(8,1);
   lcd.print(f);
   delay(1000);
   lcd.clear();
   }
   
 }

}

That code has no timing elements in it. I guess I didn't understand what you want to achieve. Can you explain it again?

Please translate the comments to English or at least use English variable names with explicit names (not "i", "f" and "t"). The variable "t" is tested several times against the value 2 but it never is set to that value.
My current understanding of your code is, that "t" is some kind of state, "i" is the current digit to be entered and "f" marks the number of unsuccessful tries to enter a valid code.
If I didn't miss anything, you can get rid of all delay() calls in your sketch. Timing stuff is easily done using millis(). Just save the value when a period starts and check against the stored value to see how much time went by.

there a alot crap in my code i know :wink: but im testing (sry)
Im making a bomb, for some airsoft play(maybe it easy to get my Q)
I will try to explain what my problem is. i "just" need some help on witch command i shall use and how they work.

you enter a rigth code, then you enter ect 10 (for the time, in minuts you have to disarm the bomb)
then efter 10 (minuts) it go off.
If you enter the rigth code before it goes off, it shall stop the timer(resert) and start from beginning.

Hope it helped ?

As I already wrote, use the millis() call to get the number of milliseconds since startup. Store that value an compare the current value to the stored one to get the milliseconds since then. To make that run as you want it, remove all the delay() calls from your sketch.

oki I will try that :smiley:
thx!