Bonsoir, je suis tout nouveau ici et je vient de me lancer il y a quelque jours dans l'ARDUINO. J'ai réussi plusieurs montage sans rien faire grillé (youpi).
Mais malheureusement aujourd'hui je vient de me heurter à un petit souci de codage.
Je m'explique.
Avec l'aide de ma carte arduino uno r3, d'un clavier 4x4 et d'un écran LCD, j'ai voulu faire un Minuteur (maxi 99H 59M 59S) mais le problème c'est que dès que je mettre moins d'une heure (ex: 10 minutes) il m'affiche 00H99959 et je n'arrive pas à trouvé le problème. Merci de me venir en aide.

voiçi le code en question :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
 
/////////////////////////////
//      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];
LiquidCrystal lcd(A0, A1, A2, A3, A4, A5); // the pins we use on the LCD
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {7, 6, 5, 4}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {3, 2, 8, 0}; //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++;
      }
    }
  }
  Hcount=(int) strtol(Hcountset, (char **)NULL, 10);
    while (Mcount < 2)
  {
    lcd.setCursor(Mcount + 7, 1);
    lcd.cursor();
    char key = keypad.getKey();
    key == NO_KEY;
    if (key != NO_KEY)
    {
      if ((key != '*')&&(key != '#'))
      {
        if(((Mcount==0) && atoi(&key)<=5)||Mcount>0){
          lcd.print(key);
          Mcountset[Mcount] = key;
          Mcount++;
        }
      }
    }
  }
  Mcount=(int) strtol(Mcountset, (char **)NULL, 10);
  while (Scount < 2)
  {
    lcd.setCursor(Scount + 10, 1);
    lcd.cursor();
    char key = keypad.getKey();
    key == NO_KEY;
    if (key != NO_KEY)
    {
      if ((key != '*')&&(key != '#'))
      {
        if(((Scount==0) && atoi(&key)<=5)||Scount>0){
            lcd.print(key);
            Scountset[Scount] = key;
            Scount++;
         }
      }
    }
  }
  Scount=(int) strtol(Scountset, (char **)NULL, 10);
  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("Activation: " );
    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("Desarmorcage reussi" );
              currentLength = 0;
              digitalWrite(ledPin3, HIGH);
              delay(2500);
              lcd.setCursor(0,1);
              lcd.print("Reset the Bomb" );
              delay(20000);
            }
      else
        {
          lcd.noCursor();
          lcd.clear();
          lcd.home();
          lcd.print("Code Faux" );
 
          if (Hcount > 0)
            {
              Hcount = Hcount - 0;
            }
 
          if (Mcount > 0)
            {
              Mcount = Mcount - 5;
            }
          if (Scount > 0)
            {
              Scount = Scount - 00;
            }
        delay(1500);
        currentLength = 0;
 
        }
      } 
    }
}
void timer()
{
  Serial.print(Scount);
  Serial.println();
 
  if (Hcount <= 0)
  {
    if ( Mcount < 0 )
    {
      lcd.noCursor();
      lcd.clear();
      lcd.home();
      lcd.print("The Bomb Has " );
      lcd.setCursor (0,1);
      lcd.print("Exploded!" );
 
      while (Mcount < 0)
      {
        digitalWrite(ledPin, HIGH); // LED on
        tone1.play(NOTE_A2, 90);
        delay(100);
        digitalWrite(ledPin, LOW); // LED off
        tone1.play(NOTE_A2, 90);
        delay(100);
        digitalWrite(ledPin2, HIGH);
        tone1.play(NOTE_A2, 90);
        delay(100);
        digitalWrite(ledPin2, LOW);
        tone1.play(NOTE_A2, 90);
        delay(100);
        digitalWrite(ledPin3, HIGH);
        tone1.play(NOTE_A2, 90);
        delay(100);
        digitalWrite(ledPin3, LOW);
        tone1.play(NOTE_A2, 90);
        delay(100);
      }
    }
  }
  lcd.setCursor (0,0);
  lcd.print ("Temps restant:" );
  if (Hcount >= 10)
    {
      lcd.setCursor (7,1);
      lcd.print (Hcount);
    }
  if (Hcount < 10)
    {
      lcd.setCursor (7,1);
      lcd.print ("0" );
      lcd.setCursor (8,1);
      lcd.print (Hcount);
    }
  lcd.print ("H" );
  if (Mcount >= 10)
    {
      lcd.setCursor (10,1);
      lcd.print (Mcount);
    }
  if (Mcount < 10)
    {
      lcd.setCursor (10,1);
      lcd.print ("0" );
      lcd.setCursor (11,1);
      lcd.print (Mcount);
    }
 
  lcd.print ("M" );
  if (Scount >= 10)
    {
      lcd.setCursor (13,1);
      lcd.print (Scount);
    }
  if (Scount < 10)
    {
      lcd.setCursor (13,1);
      lcd.print ("0" );
      lcd.setCursor (14,1);
      lcd.print (Scount);
    }
  if (Hcount <0)
    {
      Hcount = 0;
    }
  if (Mcount <0)
    {
      Hcount --;
      Mcount = 59;
    }
  if (Scount <1) // if 60 do this operation
    {
      Mcount --; // add 1 to Mcount
      Scount = 59; // reset Scount
    }
  if (Scount > 0) // do this oper. 59 times
    {
      unsigned long currentMillis = millis();
 
      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
          //lcd.clear();
        }
    }
}