asphyth | Salut a tous !
J'ai un petit soucis de codage (je découvre le C++ avec ce projet) et j'aurai besoin de votre éclaircissement !
Voilà mon projet est de faire une "bombe factice" pour l'airsoft que je pratique ! Le but étant juste d'avoir une malette comprenant un buzzer avec timer/code et de créer un décompte afin que l'équipe adverse vienne "désamorcée" la "bombe" (pas d'explosion etc c'est du factice )
J'ai donc un Arduino One, écran LCD 16x2, un buzzer, des LEDS et un clavier matriciel (1,2,3,4,5,6,7,8,9,*,0,#). J'ai récupéré des bouts de code de part et d'autre du net en les modifiants a ma sauce. Cependant je bloque fortement sur un point, le réglage du timer de la "bombe". Dans un premier temps seul le code d' "armement" était configurable via le clavier matriciel, il fonctionne très bien. Je réglait les valeurs Scount, Mcount et Hcount dans les int et le timer fonctionnait parfaitement. Mais voila que je me lance dans l'idée de configurer ce dernier avant la saisie du code. Mais la impossible de définir quoi que ce soit ! Exemple : Je défini HH:MM:SS comme suivant : 14:52:36 (un pur exemple) cela me donne en affichage sur l'écran : e: g: i (14 = 1+4 = 5 = 5ème lettre de l'alphabet = e) ... je ne sais plus par ou passer ! je pense que ce qui bloque c'est la déclaration que je fait de la ligne 245 a 247 !
Un coup de main serait de grande aide ! Merci a vous d'avance ! Voici mon code :
Code :
- /////////////////////////////
- // Airsoft Bomb //
- /////////////////////////////
- #include "LiquidCrystal.h"
- #include "Keypad.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 DefuseTimer = 0; // set timer to 0
- long secMillis = 0; // store last time for second add
- long interval = 1000; // interval for seconds
- char password[4]; // number of characters in our password
- int currentLength = 0; //defines which number we are currently writing
- int i = 0;
- int j = 0;
- char entered[4];
- int ledPin = 4; //red led
- int ledPin2 = 3; //yellow led
- int ledPin3 = 2; //green led
- char Hcountset[2];
- char Mcountset[2];
- char Scountset[2];
- char Countval[3];
- LiquidCrystal lcd(7,8,10,11,12,13); // the pins we use on the LCD
- const byte ROWS = 4; //four rows
- const byte COLS = 3; //three columns
- char keys[ROWS][COLS] = {
- {'1','2','3'},
- {'4','5','6'},
- {'7','8','9'},
- {'*','0','#'}
- };
- byte rowPins[ROWS] = {A2, A3, A4, A5}; //connect to the row pinouts of the keypad
- byte colPins[COLS] = {A0, 5, A1}; //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 output
- pinMode(ledPin2, OUTPUT); // sets the digital pin as output
- pinMode(ledPin3, OUTPUT); // sets the digital pin as output
- lcd.begin(16, 2);
- Serial.begin(9600);
- lcd.clear();
- lcd.setCursor(0,0);
- lcd.print("Definir temps : " );
- lcd.setCursor(4,1);
- lcd.print("HH:MM:SS" );
- while (Hcount < 2)
- {
- lcd.setCursor(Hcount + 4, 1);
- lcd.cursor();
- char key = keypad.getKey();
- key == NO_KEY;
- if (key != NO_KEY)
- {
- if ((key != '*')&&(key != '#'))
- {
- lcd.print(key);
- Hcountset[Hcount] = key;
- Hcount++;
- }
- }
- }
- while (Mcount < 2)
- {
- lcd.setCursor(Mcount + 7, 1);
- lcd.cursor();
- char key = keypad.getKey();
- key == NO_KEY;
- if (key != NO_KEY)
- {
- if ((key != '*')&&(key != '#'))
- {
- lcd.print(key);
- Mcountset[Mcount] = key;
- Mcount++;
- }
- }
- }
- while (Scount < 2)
- {
- lcd.setCursor(Scount + 10, 1);
- lcd.cursor();
- char key = keypad.getKey();
- key == NO_KEY;
- if (key != NO_KEY)
- {
- if ((key != '*')&&(key != '#'))
- {
- lcd.print(key);
- Scountset[Scount] = key;
- Scount++;
- }
- }
- }
- delay(1000);
-
- lcd.clear();
- lcd.setCursor(0,0);
- lcd.print("Choisir Code : " );
- while (currentLength < 4)
- {
- lcd.setCursor(currentLength + 6, 1);
- lcd.cursor();
- char key = keypad.getKey();
- key == NO_KEY;
- if (key != NO_KEY)
- {
- if ((key != '*')&&(key != '#'))
- {
- lcd.print(key);
- password[currentLength] = key;
- currentLength++;
- tone1.play(NOTE_C6, 200);
- }
- }
- }
-
-
- if (currentLength == 4)
- {
- delay(500);
- 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]);
- tone1.play(NOTE_E6, 200);
- delay(3000);
- lcd.clear();
- currentLength = 0;
- }
- }
- void loop()
- {
- timer();
- char key2 = keypad.getKey(); // get the key
-
- if (key2 == '*')
- {
-
- lcd.clear();
- lcd.setCursor(0,0);
- lcd.print("Code : " );
-
- while (currentLength < 4)
- {
-
- timer();
-
- char key2 = keypad.getKey();
- if (key2 == '#')
- {
- currentLength = 0;
- lcd.clear();
- lcd.setCursor(0,0);
- lcd.print("Code: " );
- }
- else
- if (key2 != NO_KEY)
- {
-
- lcd.setCursor(currentLength + 7, 0);
- lcd.cursor();
-
- lcd.print(key2);
- entered[currentLength] = key2;
- currentLength++;
- tone1.play(NOTE_C6, 200);
- delay(100);
- lcd.noCursor();
- lcd.setCursor(currentLength + 6, 0);
- lcd.print("*" );
- lcd.setCursor(currentLength + 7, 0);
- 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("Bomb Defused" );
- currentLength = 0;
- digitalWrite(ledPin3, HIGH);
- delay(2500);
- lcd.setCursor(0,1);
- lcd.print("Reset the Bomb" );
- delay(1000000);
- }
- else
- {
- lcd.noCursor();
- lcd.clear();
- lcd.home();
- lcd.print("Wrong Password!" );
-
- if (Countval[0] > 0)
- {
- Countval[0] = Countval[0] - 1;
- }
-
- if (Countval[1] > 0)
- {
- Countval[1] = Countval[1] - 59;
- }
- if (Countval[2] > 0)
- {
- Countval[2] = Countval[2] - 59;
- }
- delay(1500);
- currentLength = 0;
-
- }
- }
- }
- }
- void timer()
- {
- Countval[0] = Hcountset[0] + Hcountset[1];
- Countval[1] = Mcountset[0] + Mcountset[1];
- Countval[2] = Scountset[0] + Scountset[1];
- Serial.print(Countval[2]);
- Serial.println();
- if (Countval[0] <= 0)
- {
- if ( Countval[1] < 0 )
- {
- lcd.noCursor();
- lcd.clear();
- lcd.home();
- lcd.print("The Bomb Has " );
- lcd.setCursor (0,1);
- lcd.print("Exploded!" );
-
- while (Countval[1] < 0)
- {
- digitalWrite(ledPin, HIGH); // sets the LED on
- tone1.play(NOTE_A2, 90);
- delay(100);
- digitalWrite(ledPin, LOW); // sets the LED off
- tone1.play(NOTE_A2, 90);
- delay(100);
- digitalWrite(ledPin2, HIGH); // sets the LED on
- tone1.play(NOTE_A2, 90);
- delay(100);
- digitalWrite(ledPin2, LOW); // sets the LED off
- tone1.play(NOTE_A2, 90);
- delay(100);
- digitalWrite(ledPin3, HIGH); // sets the LED on
- tone1.play(NOTE_A2, 90);
- delay(100);
- digitalWrite(ledPin3, LOW); // sets the LED off
- tone1.play(NOTE_A2, 90);
- delay(100);
- }
- }
- }
- lcd.setCursor (0,1); // sets cursor to 2nd line
- lcd.print ("Timer:" );
- if (Countval[0] >= 10)
- {
- lcd.setCursor (7,1);
- lcd.print (Countval[0]);
- }
- if (Countval[0] < 10)
- {
- lcd.setCursor (7,1);
- lcd.write ("0" );
- lcd.setCursor (8,1);
- lcd.print (Countval[0]);
- }
- lcd.print (":" );
- if (Countval[1] >= 10)
- {
- lcd.setCursor (10,1);
- lcd.print (Countval[1]);
- }
- if (Countval[1] < 10)
- {
- lcd.setCursor (10,1);
- lcd.write ("0" );
- lcd.setCursor (11,1);
- lcd.print (Countval[1]);
- }
-
- lcd.print (":" );
- if (Countval[2] >= 10)
- {
- lcd.setCursor (13,1);
- lcd.print (Countval[2]);
- }
- if (Countval[2] < 10)
- {
- lcd.setCursor (13,1);
- lcd.write ("0" );
- lcd.setCursor (14,1);
- lcd.print (Countval[2]);
- }
- if (Countval[0] <0)
- {
- Countval[0] = 0;
- }
- if (Countval[1] <0)
- {
- Countval[0] --;
- Countval[1] = 59;
- }
- if (Countval[2] <1) // if 60 do this operation
- {
- Countval[1] --; // add 1 to Mcount
- Countval[2] = 59; // reset Scount
- }
- if (Countval[2] > 0) // do this oper. 59 times
- {
- unsigned long currentMillis = millis();
-
- if(currentMillis - secMillis > interval)
- {
- tone1.play(NOTE_G5, 150);
- secMillis = currentMillis;
- Countval[2] --; // add 1 to Scount
- digitalWrite(ledPin, HIGH); // sets the LED on
- digitalWrite(ledPin2, HIGH); // sets the LED on
- delay(100); // waits for a second
- digitalWrite(ledPin, LOW); // sets the LED off
- digitalWrite(ledPin2, LOW); // sets the LED off
- delay(100); // waits for a second
- //lcd.clear();
- }
- }
- }
|
Message édité par asphyth le 25-01-2014 à 23:26:41 ---------------
-> Mon Feed Back <- -> Mes Ventes <-
|