Bonjour à tous
Je suis sur un projet de malette multijeux pour l'airsoft
Je prends 2 jeux que j'ai créé et je les rassemble sur un seul sketch que je programme avec switch case
Pour le moment je suis sur la partie sabotage
J'active les variables des signaux sonores dans le switch case et les boucles if des signaux sonores sont à l'exterieur du switch case
Pour l'amorcage ,j'ai fait un signal qui accélère et qui decelere pour le désamorçage qui fonctionne très bien isolé mais qui ne fonctionne plus une fois intégré dans le sketch
L'amorcage (clignote1)fait bien son cycle mais la variable etatSignal reste à l'état bas
J'ai réussi à le faire fonctionner en prenant le code des signaux sonores amorçage désamorçage et en construisant autour le programme en verifiant que ça marche à chaque étape,mais j'ai ensuite ajouté un son pour le mode radar et là ça ne fonctionne plus.je l'enlève ça ne refonctionne pas.
A côté de ça les signaux sonores du temps restant et de fin de partie ont toujours fonctionné
Voilà plusieurs semaines que je bloque là dessus ,mais je suis sûr que c'est un problème basique mais là je ne vois plus du tout de quel côté chercher
Si quelqu'un pouvait m'aiguiller
Merci
J'espère j'ai bien présenté le code
#include <TM1637.h>
#include<LiquidCrystal.h>
LiquidCrystal lcd (24,26,31,32,33,34);#include<TM1637Display.h>
#define CLK1 2
#define DIO1 3
TM1637Display displayA(CLK1, DIO1);
#define CLK2 4
#define DIO2 5
TM1637Display displayB(CLK2, DIO2);
#define nbMilliSecondes(temps) ((temps % 1000) / 10)
#define nbSecondes(temps) ((temps / 1000) % 60)
#define nbMinutes(temps) (((temps / 1000) / 60) % 60)
unsigned long chronoA = 1200000;//70000; //c70 secondes pour essais
unsigned long tpsRestantA;
unsigned long tpsLimiteA = chronoA + millis();
unsigned long memo_temps_restantA;
//les etapes
unsigned long tpsPasseA;
unsigned long chronoB = 1200000;//70000; //c70 secondes pour essais
unsigned long tpsRestantB;
unsigned long tpsLimiteB = chronoB + millis();
unsigned long memo_temps_restantB;
//les etapes
unsigned long tpsPasseB;
//const int boutonPlus = 10 ;
//int etatBoutonPlus = 0 ;
//byte boutonMoins = 9 ;
//const int boutonMoins = 9;
//int etatBoutonMoins = 0 ;
//const int BP_verrouille = 11;
//int etatBP_verrouille = 0 ;
int etatPrecedantBoutonPlus = 0 ;
int etatPrecedantBoutonMoins = 0 ;
int etatPrecedantBP_verrouille = 0 ;
int valeurMenu=0;
unsigned long tpsAffichageEcranClignote ;
boolean signalRadar = false ;
unsigned long bipRadar ;
unsigned long tempoSignalRadar ;
boolean bipRadarNonLance = true ;
boolean sonAmorcageLu = false ;
boolean sonDesamorcageLu = false ;
boolean signalFinLu = false ;
unsigned long tempssignalfinMillis ;
boolean A10min = false ;
boolean A5min = false ;
boolean A4min = false ;
boolean A3min = false ;
boolean A2min = false ;
boolean A1min = false ;
boolean B10min = false ;
boolean B5min = false ;
boolean B4min = false ;
boolean B3min = false ;
boolean B2min = false ;
boolean B1min = false ;
//signal temps restantA
boolean clignotetpsrestantA = false;
boolean goclignotetpsrestantA = false;
unsigned long antirepetitiongoclignotetpsrestantAMillis=0;
boolean antirepetitiongoclignotetpsrestantA = false;
int nbeclignotetpsrestantA =0 ;
unsigned long tempsclignotetpsrestantA ;
int nbeclignotagetpsrestantA = 0 ;
byte BP_verrouille = 11 ;
boolean BP_verrouilleRelache = true ;
byte BP1 = 9 ;
boolean BP1Relache = true ;
byte BP2 = 10 ;
boolean BP2Relache = true ;
int led1 = 12 ;//12
int led2 = 13 ;
int signal = 14;
int tpsSignal = 50 ;
int tpsInterSignal = 250 ;
int tpsInterSignal2 = 10 ;
boolean etatled1 = false;
boolean etatled2 = false ;
boolean clignote1 = false ;
boolean clignote2 = false ;
boolean etatSignal = false ;
int nbeclignote1 = 0 ;
int nbeclignote2 = 0 ;
unsigned long debutAmorcageMillis;
unsigned long temps1 ;
unsigned long temps2 ;
void setup() {
lcd.begin(16,2);
pinMode(BP1,INPUT_PULLUP);
pinMode(led1,OUTPUT);
pinMode(BP2,INPUT_PULLUP);
pinMode(led2,OUTPUT);
pinMode(signal,OUTPUT);
Serial.begin(9600);
displayA.setBrightness(7);
displayA.showNumberDecEx((nbMinutes(chronoA) * 100) + nbSecondes(chronoA), 0b11100000, true);
displayB.setBrightness(7);
displayB.showNumberDecEx((nbMinutes(chronoB) * 100) + nbSecondes(chronoB), 0b11100000, true);
}
void compteareboursA() {
tpsRestantA = tpsLimiteA - millis(); tpsPasseA = chronoA - tpsRestantA;
if (tpsRestantA > 60000) displayA.showNumberDecEx((nbMinutes(tpsRestantA) * 100) + nbSecondes(tpsRestantA), 0b11100000, true);
else {
if (tpsRestantA <= 0) {
displayA.showNumberDecEx(0000, 0b11100000, true);
}
else {
displayA.showNumberDecEx((nbSecondes(tpsRestantA) * 100) + nbMilliSecondes(tpsRestantA), 0b11100000, true);
}
}
}
void compteareboursB() {
tpsRestantB = tpsLimiteB - millis(); tpsPasseB = chronoB - tpsRestantB;
if (tpsRestantB > 60000) displayB.showNumberDecEx((nbMinutes(tpsRestantB) * 100) + nbSecondes(tpsRestantB), 0b11100000, true);
else {
if (tpsRestantB <= 0) {
displayB.showNumberDecEx(0000, 0b11100000, true);
}
else {
displayB.showNumberDecEx((nbSecondes(tpsRestantB) * 100) + nbMilliSecondes(tpsRestantB), 0b11100000, true);
}
}
}
void loop() {
Serial.print(" valeurMenu:");
Serial.print(valeurMenu);
//Serial.print(" signalRadar:");
//Serial.print(signalRadar);
Serial.print(" clignote1:");
Serial.print(clignote1);
Serial.print(" clignote2:");
Serial.print(clignote2);
Serial.print(" signalRadar:");
Serial.print(signalRadar);
Serial.print(" etatSignal:");
Serial.print(etatSignal);
Serial.print(" tpsInterSignal:");
Serial.println(tpsInterSignal);
if(etatSignal == true){
digitalWrite(signal,HIGH);}
else{ digitalWrite (signal,LOW);}
if (digitalRead (BP_verrouille)){
BP_verrouilleRelache = true ;
}
if (digitalRead (BP1)){
BP1Relache = true ;
}
if (digitalRead (BP2)){
BP2Relache = true ;
}
///////////////////////////////////////////////signal amorcage
if(clignote1 == true){
debutAmorcageMillis = millis();
if ((debutAmorcageMillis - temps1) < tpsSignal){
etatSignal = true ;}
if ((debutAmorcageMillis - temps1) > tpsSignal){
etatSignal = false ;}
if ((debutAmorcageMillis - temps1)> tpsInterSignal){
temps1 = debutAmorcageMillis;
tpsInterSignal = tpsInterSignal - 10;
if (tpsInterSignal<10){
clignote1 = false ;
etatSignal = false ;
tpsInterSignal = 250 ;
}
}
}
//////////////////////////////////////////////signal desamorcage
if(clignote2 == true){
if ((millis() - temps1) < tpsSignal){
etatSignal = true ;}
if ((millis() - temps1) > tpsSignal){
etatSignal = false ;}
if ((millis() - temps1)> tpsInterSignal2){
temps1 = millis();
tpsInterSignal2 = tpsInterSignal2 + 10 ;
if (tpsInterSignal2>250){
clignote2 = false ;
etatSignal = false ;
tpsInterSignal2 = 10 ;
}
}
}
///////////////////////////////signal temps restantA
if((goclignotetpsrestantA ==true)&&(antirepetitiongoclignotetpsrestantA==false)){
(clignotetpsrestantA = true);
goclignotetpsrestantA = false;
}
if(clignotetpsrestantA ==true){
if (nbeclignotetpsrestantA < nbeclignotagetpsrestantA){
if ((millis() - tempsclignotetpsrestantA) > 100){
etatSignal = !etatSignal;
// digitalWrite(led1,etatled1);
tempsclignotetpsrestantA = millis();
nbeclignotetpsrestantA ++ ;
}
}
if (nbeclignotetpsrestantA >=nbeclignotagetpsrestantA ){
clignotetpsrestantA = false ;
nbeclignotetpsrestantA = 0 ;
}
}
/////////////////////////////////////////////////signal radar
if(signalRadar == true){
if ((millis() - bipRadar) < 50){
etatSignal = true ;
}else{
if ((millis() - bipRadar) < 100){
etatSignal = false ;
}else{
if ((millis() - bipRadar) < 150){
etatSignal = true ;
}else{
if ((millis() - bipRadar) < 1000){
etatSignal = false ;
}else{
if ((millis() - bipRadar) < 1050){
etatSignal = true ;
}else{
if ((millis() - bipRadar) < 1100){
etatSignal = false ;
}else{
if ((millis() - bipRadar) < 1150){
etatSignal = true ;
}else{
etatSignal = false ;
}
if ((millis() - bipRadar) > 80000){
bipRadar = millis() ;
}
}
}
}
}
}
}
}
switch (valeurMenu){
case 0:
///////selection mode(1 seul pour l'instant)
if((millis() - tpsAffichageEcranClignote ) < 1000){
lcd.clear();
lcd.setCursor(4, 0);
lcd.print("sabotage");
}
if((millis() - tpsAffichageEcranClignote ) > 1000){
lcd.clear();
}
if((millis() - tpsAffichageEcranClignote ) > 2000){
tpsAffichageEcranClignote = millis();
}
if ((!digitalRead (BP_verrouille))&&(BP_verrouilleRelache==true)){
BP_verrouilleRelache = false ;
valeurMenu = 2;
}
break;
case1 :
///////selection mode (en attente)
if((millis() - tpsAffichageEcranClignote ) < 1000){
lcd.clear();
lcd.setCursor(4, 0);
lcd.print("prise de");
lcd.setCursor(3, 1);
lcd.print("territoire");
}
if((millis() - tpsAffichageEcranClignote ) > 1000){
lcd.clear();
}
if((millis() - tpsAffichageEcranClignote ) > 2000){
tpsAffichageEcranClignote = millis();
}
break ;
case 2 :
////////reglage temps sabotage
if((millis() - tpsAffichageEcranClignote ) < 1000){
lcd.clear();
lcd.setCursor(4, 0);
lcd.print("sabotage");
}
if((millis() - tpsAffichageEcranClignote ) > 1000){
lcd.clear();
lcd.setCursor(4, 0);
lcd.print("sabotage");
lcd.setCursor(1, 1);
lcd.print("reglage temps");
}
if((millis() - tpsAffichageEcranClignote ) > 2000){
tpsAffichageEcranClignote = millis();
}
if ((!digitalRead (BP_verrouille))&&(BP_verrouilleRelache==true)){
BP_verrouilleRelache = false ;
tempoSignalRadar = millis();
valeurMenu = 3;
}
if((!digitalRead (BP2))&&(BP2Relache==true)) {
BP2Relache = false ;
chronoA = chronoA + 60000 ;
chronoB = chronoA ;
// tpsRestantA = tpsRestantA + 60000 ;
// tpsRestantB = tpsRestantA ;
//nonRepetitionMillis = millis();
//nonRepetition = true;
tpsLimiteA = chronoA + millis();
tpsRestantA = tpsLimiteA - millis();
memo_temps_restantA = tpsRestantA ;
compteareboursA();
/*tpsLimiteB = chronoB + millis();
tpsRestantB = tpsLimiteB - millis();
memo_temps_restantB = tpsRestantB ;
compteareboursB();*/
}
if((!digitalRead (BP1))&&(BP1Relache==true)) {
BP1Relache = false;
chronoA = chronoA - 60000 ;
tpsLimiteA = chronoA + millis();
tpsRestantA = tpsLimiteA - millis();
memo_temps_restantA = tpsRestantA ;
compteareboursA();
}
tpsLimiteA = chronoA + millis();
memo_temps_restantA = tpsRestantA ;
tpsLimiteA = chronoA + millis(); tpsRestantA = tpsLimiteA - millis();
break ;
case 3 :
////////sabotage mode radar
tpsLimiteA = chronoA + millis();
lcd.clear();
lcd.setCursor(4, 0);
lcd.print("sabotage");
lcd.setCursor(3, 1);
lcd.print("mode radar");
chronoB = chronoA ;
if ((millis() - tempoSignalRadar) > 10000 ){
signalRadar = true ;
if (bipRadarNonLance == true){
bipRadar = millis();
bipRadarNonLance = false ;
}
}
if (!digitalRead(BP1)){
(valeurMenu) = 4;
clignote2 = false ;
tpsInterSignal2 = 10 ;
clignote1 = true;
debutAmorcageMillis = millis();
signalRadar = false ;
etatSignal = false ;
}
A10min = false ;
A5min = false ;
A4min = false ;
A3min = false ;
A2min = false ;
A1min = false ;
break ;
case 4 :
////////sabotage bombe amorcee
lcd.clear();
lcd.setCursor(4, 0);
lcd.print("sabotage");
lcd.setCursor(1, 1);
lcd.print("bombe amorcee");
signalRadar = false ;
if (!digitalRead(BP2)){
clignote2 = true ;
clignote1 = false ;
tpsInterSignal = 250 ;
tempoSignalRadar = millis() ;
valeurMenu = 3 ;
bipRadarNonLance = true ;
}
compteareboursA();
if (((tpsRestantA / 1000) == 601)&&(!A10min)) {
nbeclignotagetpsrestantA = 20;
goclignotetpsrestantA = true;
A10min = true ;
} else {
if (((tpsRestantA / 1000) == 301) &&(!A5min)) {
nbeclignotagetpsrestantA = 10;
goclignotetpsrestantA = true;
A5min = true ;
}else{
if (((tpsRestantA / 1000) == 241)&&(!A4min)) {
nbeclignotagetpsrestantA = 8;
goclignotetpsrestantA = true;
A4min = true;
} else {
if (((tpsRestantA / 1000) == 181) && (!A3min)) {
nbeclignotagetpsrestantA = 6;
goclignotetpsrestantA = true;
A3min = true;
}else{
if (((tpsRestantA / 1000) == 121) && (!A2min)) {
nbeclignotagetpsrestantA = 4;
goclignotetpsrestantA = true;
A2min = true;
} else {
if (((tpsRestantA / 1000) == 61) && (!A1min)) {
nbeclignotagetpsrestantA = 2;
goclignotetpsrestantA = true;
A1min = true;
}
}
}
}
}
}
if ((tpsPasseA) >= chronoA){
compteareboursA(); Serial.println(F(" fin des if"));
displayA.showNumberDecEx(0000, 0b11100000, true);
valeurMenu = 5 ;
}
break;
case 5 :
////////bombe explosee partie finie
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("sabotage termine");
lcd.setCursor(1, 1);
lcd.print("bombe explosee");
if(signalFinLu == false){
etatSignal = true;
//digitalWrite (signal , HIGH);
tempssignalfinMillis = millis();
signalFinLu = true;
}
if ((millis()-tempssignalfinMillis) > 5000 ) {
etatSignal = false ;
}
break ;
}//////////////////////////////////fin de switch case
}