area control

Boa tarde, estou tentando e tentando mas não estou conseguindo.
Quero algo simples com keypad, 2 botões e 2 leds.
Está decrementando tempo introduzido pelo utilizador de forma h:m:s na linha 2 previamente introduzido e se:
Premir o botão1 durante 5s mostra na linha2 "equipa1:(tempo incrementando)" e o led verde a piscar
Se outra pessoa carregar no outro botão como já está uma equipa em contagem, esta deve pausar a contagem e começar a contagem da nova equipa (tem que carregar no botão durante 5s para cancelar + 5s para contar nova equipa = 10s), mostrando na linha2 "equipa 2:(tempo incrementando) e o led vermelho liga apagando o verde, se a equipa 1 conseguir voltar a tomar o controlo o tempo deve continuar onde parou antes de perder o controlo.
No final do tempo terminar deve mostrar qual a equipa com mais tempo acumulado.
Alguém me consegue ajudar com este código por favor?
Isto depois é para implementar num projecto, só falta mesmo isto.
Obrigado

Ajudar é diferente de "Facam este código para mim.".

Que é que já fizeste? Porque é que não meteste aqui o que já fizeste?

não falaste em LCD, mas fiquei a entender que querias um LCD a mostrar o tempo... é verdade?

sim quero lcd.
nao meti o codigo porque o codigo usa variaveis de metodos etc e a parte onde preciso de ajuda apenas é uma fracção do programa.
Para tentar explicar o que fiz e/ou onde estou com dificuldade, se clicar na tecla # vai para um menu de configuracao onde se pode configurar o codigo para para armar a bomba(admin), tempo de jogo(time), tempo de tomar controlo e de retirar controlo. Caso contrario as variaveis mantêm o valor com que foram atribuidas.
Tem que ser introduzido o codigo admin para armar a bomba e caso o mesmo for inserido correctamente a bomba fica armada, quando está armada o tempo começa a decrementar, se chegar a 0 rebenta. Mesmo assim penso que o codigo nao esta correcto. e nao vejo como conseguir fazer com que de alguma forma cada equipa quando esta em controlo fique somando o tempo e caso o tempo seja pausado e mais tarde retomando continue e nao volte ao 0. no final mostrar a equipa com mais tempo.

case '2': //AREA CONTROL
clearLCD();
delay(2000);
selectLineOne();
Serial.print("JOGO: AREA CONTROL");
clearLCD();

switch (bombState) {
case READY:
while (count < (sizeof(ArmCode) - 1)) {//loop until the full and correct arm code is entered

selectLineTwo();
Serial.print("Enter ArmCode");

selectLineOne();
Serial.print("Code"); //prompt for arm code
Serial.print(": ");

char key;

do{
key = keypad.getKey();
}
while(key == NO_KEY);

code = (code * 10) + (key - 48); //stores the current correct digits for display later

if(key == '#' && configMenuFlag == 0) {//check if user wants to enter menu
//key = '\0';
configMenu();// enter menu
count = 0;
code = 0;
clearLCD();

}

else if(key == ArmCode[count]) {//if the key matches the code
// key = '\0';
count++;
configMenuFlag = 1;//once the code is started, the menu cannot be entered
}

else { //if the key does not match the code, reset
count = 0;
code = 0;
configMenuFlag = 1;//once the code is started, the menu cannot be entered
clearLCD();
}

selectLineOne();
Serial.print("Code"); //prompt for arm code
Serial.print(": ");
Serial.print(code);//display correct digits that have been entered

}//end while

clearLCD();
bombState = ARMED;//when the correct code has been entered, move to armed state
count = 0;
code = 0;

break;
/***********************************************************
*Armed *

************************************************************/
case ARMED:

do{
countdown();//displays countdown while simultaneously checking for disarm code

if (second == 0 && minute == 0 && hour == 0) {
code = 0;
clearLCD();
bombState = DETONATED; //clear LCD and set bomb state to "detonated" when timer runs out
break;
}
//if the correct code is entered, move to disarmed state
sw_state1 = digitalRead(switchPin1);
sw_state2 = digitalRead(switchPin2);

if(equipa=false){
if (sw_state1 == HIGH && sw_laststate1 == LOW){ // for button pressing
start_hold = millis(); // mark the time
if ((millis() - start_hold) >= HOLD_DELAY){
//allow = true; // allow LED state changes
equipa1=true;
sw_laststate1 = sw_state1;
digitalWrite(ledPin1, led_state1);
selectLineTwo();
Serial.print("Equipa Vermelha no Controlo"); //prompt for arm code
}
}
equipa=true;

if(sw_state2 == HIGH && sw_laststate2 == LOW){
start_hold = millis(); // mark the time
if ((millis() - start_hold) >= HOLD_DELAY){
//allow = true; // allow LED state changes
equipa2=true;
sw_laststate2 = sw_state2;
digitalWrite(ledPin2, led_state2);
selectLineTwo();
Serial.print("Equipa Azul no Controlo"); //prompt for arm code
}
}
equipa=true;

}
else{

if (/allow == true &&/ sw_state1 == HIGH && sw_laststate1 == HIGH){ // if button remains pressed
if ((millis() - start_hold) >= HOLD_DELAY2){ // for longer than x/1000 sec(s)
led_state1 = led_state2; // change state of LED
//allow = false;
equipa1=true;
selectLineTwo();
Serial.print("Equipa Vermelha no Controlo"); //prompt for arm code
}// prevent multiple state changes
}
sw_laststate1 = sw_state1;
digitalWrite(ledPin1, led_state1);

if (/allow == true &&/ sw_state2 == HIGH && sw_laststate2 == HIGH){ // if button remains pressed
if ((millis() - start_hold) >= HOLD_DELAY2){ // for longer than x/1000 sec(s)
led_state1 = led_state2; // change state of LED
//allow = false;
equipa1=true;
selectLineTwo();
Serial.print("Equipa Vermelha no Controlo"); //prompt for arm code
}// prevent multiple state changes
}
sw_laststate2 = sw_state2;
digitalWrite(ledPin2, led_state2);
}

}while((countdown(second))>0);//end do
//Serial.print("Equipa: " (x) " Ganhou"); //prompt for arm code

break;

case '3': //WHIRE BOMB
clearLCD();
delay(2000);
selectLineOne();
Serial.print("JOGO: WHIRE BOMB");
clearLCD();

break;

case '4'://exit case
exitMenu = 1;//exit menu if 4 is pressed
break;

}//end switch
}
while(exitMenu == 0); //sair do programa //end menuOpcoes

É impossível teres um programa que funcione com delays de 2 segundos e peca feedback a um humano. Imagina que queres mudar o canal da tua TV... e tens de esperar dois segundos até que o botão esteja activo. Ias gostar disso?

Outra coisa que não percebi é criares um bloco do{} sem condicão no final...

De resto, peco desculpa, mas agora estou sem cabeca para olhar para o resto. No entanto, existem bibliotecas para implementar menus no Arduino. É caso de procurar.

Amanhã dou outra vista de olhos.

tem delay de 2s a mostrar o texto "JOGO: AREA CONTROL"" nao esta a pedir para introduzir nd

Talvez seja isso que tu pretendes... mas não é isso que o código faz:

clearLCD();  //LIMPA LCD.
      delay(2000);   // ESPERA 2 SEGUNDOS SEM NADA
      selectLineOne();  //muda de linha...
      Serial.print("JOGO: AREA CONTROL");  //envia algo para a serial (aqui suponho que mais tarde seja para o LCD)
      clearLCD(); //limpa o LCD de novo...

Uma questão, este código funciona? Ou faz alguma coisa sequer?

isso ja eu tenho feito. nao pedi isso.

Este código esta a fazer com que a equipa em controlo seja a vencedora mas eu queria fazer isto durante o tempo não ter chegado a 0 e que a equipa vencedora fosse a que tivesse mais tempo em controlo.

case '2': //AREA CONTROL
clearLCD();
delay(2000);
selectLineOne();
Serial.print("JOGO: AREA CONTROL");
clearLCD();

switch (bombState) {
case READY:
while (count < (sizeof(ArmCode) - 1)) {//loop until the full and correct arm code is entered

selectLineTwo();
Serial.print("Enter ArmCode");

selectLineOne();
Serial.print("Code"); //prompt for arm code
Serial.print(": ");

char key;

do{
key = keypad.getKey();
}
while(key == NO_KEY);

code = (code * 10) + (key - 48); //stores the current correct digits for display later

if(key == '#' && configMenuFlag == 0) {//check if user wants to enter menu
//key = '\0';
configMenu();// enter menu
count = 0;
code = 0;
clearLCD();

}

else if(key == ArmCode[count]) {//if the key matches the code
// key = '\0';
count++;
configMenuFlag = 1;//once the code is started, the menu cannot be entered
}

else { //if the key does not match the code, reset
count = 0;
code = 0;
configMenuFlag = 1;//once the code is started, the menu cannot be entered
clearLCD();
}

selectLineOne();
Serial.print("Code"); //prompt for arm code
Serial.print(": ");
Serial.print(code);//display correct digits that have been entered

}//end while

clearLCD();
bombState = ARMED;//when the correct code has been entered, move to armed state
count = 0;
code = 0;

break;
/***********************************************************
*Armed *

*************************************************************/
case ARMED:

countdown();//displays countdown while simultaneously checking for disarm code

if (second == 0 && minute == 0 && hour == 0) {
code = 0;
clearLCD();
bombState = DETONATED; //clear LCD and set bomb state to "detonated" when timer runs out
break;
}
//if the correct code is entered, move to disarmed state
sw_state1 = digitalRead(switchPin1);
sw_state2 = digitalRead(switchPin2);

if(equipa=false){
if (sw_state1 == HIGH && sw_laststate1 == LOW){ // for button pressing
start_hold = millis(); // mark the time
if ((millis() - start_hold) >= HOLD_DELAY){
//allow = true; // allow LED state changes
equipa1=true;
sw_laststate1 = sw_state1;
digitalWrite(ledPin1, led_state1);
selectLineTwo();
Serial.print("Equipa Vermelha no Controlo"); //prompt for arm code
}
}
equipa=true;

if(sw_state2 == HIGH && sw_laststate2 == LOW){
start_hold = millis(); // mark the time
if ((millis() - start_hold) >= HOLD_DELAY){
//allow = true; // allow LED state changes
equipa2=true;
sw_laststate2 = sw_state2;
digitalWrite(ledPin2, led_state2);
selectLineTwo();
Serial.print("Equipa Azul no Controlo"); //prompt for arm code
}
}
equipa=true;

}
else{

if (/allow == true &&/ sw_state1 == HIGH && sw_laststate1 == HIGH){ // if button remains pressed
if ((millis() - start_hold) >= HOLD_DELAY2){ // for longer than x/1000 sec(s)
led_state1 = led_state2; // change state of LED
//allow = false;
equipa1=true;
selectLineTwo();
Serial.print("Equipa Vermelha no Controlo"); //prompt for arm code
}// prevent multiple state changes
}
sw_laststate1 = sw_state1;
digitalWrite(ledPin1, led_state1);

if (/allow == true &&/ sw_state2 == HIGH && sw_laststate2 == HIGH){ // if button remains pressed
if ((millis() - start_hold) >= HOLD_DELAY2){ // for longer than x/1000 sec(s)
led_state1 = led_state2; // change state of LED
//allow = false;
equipa1=true;
selectLineTwo();
Serial.print("Equipa Vermelha no Controlo"); //prompt for arm code
}// prevent multiple state changes
}
sw_laststate2 = sw_state2;
digitalWrite(ledPin2, led_state2);
}

break;