Bonjour,
je rencontre des difficultés en arduino:
le projet est une minuterie de 15mn sur un écran LCD, j'utilise aussi un bouton poussoir, un buzzer et des LEDs.
tout fonctionne sauf l'affichage du compte à rebours sur l'écran LCD : il reste figé a 15 minutes... Est-ce un problème de code de montage ou les deux?
Voici le code :
#include
#define BUZ 10
#define RED 11
#define YEL 12
#define GRN 13
const int bouton = 9;
const int rs = 2, en = 3, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
long timeInit=0;
int tHour=0;
int tMin=15;
int tSec=00;
int timeToCounter(int h,int m,int s) {
return h*3600+m*60+s;
}
void counterToTime(long cnt) {
tHour=(cnt/3600);
tMin= (cnt%3600)/60;
tSec = ((cnt%3600)%60);
}
void setup() {
pinMode(RED, OUTPUT);
pinMode(YEL, OUTPUT);
pinMode(GRN, OUTPUT);
pinMode(BUZ, OUTPUT);
pinMode(bouton, INPUT);
lcd.begin(16, 2);
analogWrite(8,15);
lcd.print("Il reste :");
timeInit=timeToCounter(tHour,tMin,tSec);
}
void loop() {
int test = digitalRead(bouton);
if(test==LOW) {
counterToTime(timeInit);
lcd.setCursor(0, 1);
lcd.print(tHour);
lcd.print(" h ");
lcd.print(tMin);
lcd.print(" m ");
lcd.print(tSec);
lcd.print(" s");
delay(1000);
timeInit=timeInit-1;
digitalWrite(GRN, HIGH);
delay(540000);
digitalWrite(GRN, LOW);
digitalWrite(YEL, HIGH);
delay(180000);
digitalWrite(YEL, LOW);
digitalWrite(RED, HIGH);
delay(120000);
digitalWrite(RED, LOW);
delay(1000);
digitalWrite(RED, HIGH);
delay(1000);
digitalWrite(RED, LOW);
delay(1000);
digitalWrite(RED, HIGH);
delay(1000);
digitalWrite(RED, LOW);
delay(1000);
digitalWrite(RED, HIGH);
delay(1000);
digitalWrite(RED, LOW);
delay(1000);
digitalWrite(RED, HIGH);
delay(1000);
digitalWrite(RED, LOW);
delay(1000);
digitalWrite(RED, HIGH);
delay(1000);
digitalWrite(RED, LOW);
delay(1000);
digitalWrite(RED, HIGH);
delay(1000);
digitalWrite(RED, LOW);
delay(1000);
digitalWrite(RED, HIGH);
delay(1000);
digitalWrite(RED, LOW);
delay(1000);
digitalWrite(RED, HIGH);
delay(1000);
digitalWrite(RED, LOW);
delay(1000);
digitalWrite(RED, HIGH);
delay(1000);
digitalWrite(RED, LOW);
delay(1000);
digitalWrite(RED, HIGH);
delay(1000);
digitalWrite(RED, LOW);
delay(1000);
digitalWrite(RED, HIGH);
delay(1000);
digitalWrite(RED, LOW);
delay(1000);
digitalWrite(RED, HIGH);
delay(1000);
digitalWrite(RED, LOW);
delay(1000);
digitalWrite(RED, HIGH);
delay(1000);
digitalWrite(RED, LOW);
delay(1000);
digitalWrite(RED, HIGH);
delay(1000);
digitalWrite(RED, LOW);
delay(1000);
digitalWrite(RED, HIGH);
delay(1000);
digitalWrite(RED, LOW);
delay(1000);
digitalWrite(RED, HIGH);
delay(1000);
digitalWrite(RED, LOW);
delay(1000);
digitalWrite(RED, HIGH);
delay(1000);
digitalWrite(RED, LOW);
delay(1000);
digitalWrite(RED, HIGH);
delay(1000);
digitalWrite(RED, LOW);
delay(1000);
digitalWrite(RED, HIGH);
delay(1000);
digitalWrite(RED, LOW);
delay(1000);
digitalWrite(RED, HIGH);
delay(1000);
digitalWrite(RED, LOW);
delay(1000);
digitalWrite(RED, HIGH);
delay(1000);
digitalWrite(RED, LOW);
delay(1000);
digitalWrite(RED, HIGH);
delay(1000);
digitalWrite(RED, LOW);
delay(1000);
digitalWrite(RED, HIGH);
delay(1000);
digitalWrite(RED, LOW);
delay(1000);
digitalWrite(RED, HIGH);
delay(1000);
digitalWrite(RED, LOW);
delay(1000);
digitalWrite(RED, HIGH);
delay(1000);
digitalWrite(RED, LOW);
delay(1000);
digitalWrite(RED, HIGH);
delay(1000);
digitalWrite(RED, LOW);
delay(1000);
digitalWrite(RED, HIGH);
delay(1000);
digitalWrite(RED, LOW);
delay(1000);
digitalWrite(RED, HIGH);
delay(1000);
digitalWrite(RED, LOW);
delay(1000);
digitalWrite(RED, HIGH);
delay(1000);
digitalWrite(RED, LOW);
delay(1000);
digitalWrite(RED, HIGH);
delay(1000);
digitalWrite(RED, LOW);
tone (10, 750);
delay(200);
noTone(10);
delay(100);
tone (10, 1000) ;
delay(200);
noTone(10);
delay(1000);
tone (10, 750);
delay(200);
noTone(10);
delay(100);
tone (10, 1000) ;
delay(200);
noTone(10);
delay(1000);
}
else {
digitalWrite(RED, LOW);
digitalWrite(YEL, LOW);
digitalWrite(GRN, LOW);
noTone(10);
}
}
P.S.: existe-t-il une autre commande pour faire clignoter la led rouge pendant la dernière minute plutôt que d'utiliser :
_
delay(1000); |
digitalWrite(RED, HIGH); |_ x30
delay(1000); |
digitalWrite(RED, LOW); _|
ça serait sympa de partager la solution
merci d'avance!
Lista de comentários
Réponse : le problèmes est que l'écrans gâte
Explications : parce que out fonctionne sauf l'affichage du compte à rebours sur l'écran LCD