Étape 3: Étape 3: programmation
Copiez le Code suivant à l’Arduino :
int a = 2 ; Pour afficher le segment « a »
int b = 3 ; Pour afficher le segment « b »
int c = 4 ; Pour afficher le segment « c »
int d = 5 ; Pour afficher le segment « d »
int e = 6 ; Pour afficher le segment « e »
int f = 8 ; Pour afficher le segment « f »
int g = 9 ; Pour afficher le segment « g »
int LDR = A0 ; LDR
int LDRValue = 0 ;
tril int = 12 ; moteur
void setup() {}
pinMode (a, sortie) ; A
pinMode (b, sortie) ; B
pinMode (c, sortie) ; C
pinMode (d, sortie) ; D
pinMode (e, sortie) ; E
pinMode (f, sortie) ; F
pinMode (g, sortie) ; G
pinMode(LDR,INPUT) ; LDR
pinMode(tril,OUTPUT) ; moteur
Serial.Begin(9600) ;
}
void displayDigit (int digit) {}
Conditions d’affichage segment une
Si (chiffre! = 1 & & chiffre! = 4)
digitalWrite(a,HIGH) ;
Conditions d’affichage de segment b
Si (chiffre! = 5 & & chiffre! = 6)
digitalWrite(b,HIGH) ;
Conditions d’affichage de segment c
Si (chiffre! = 2)
digitalWrite(c,HIGH) ;
Conditions d’affichage segment d
Si (chiffre! = 1 & & chiffre! = 4 & & chiffre! = 7)
digitalWrite(d,HIGH) ;
Conditions d’affichage de segment e
Si (chiffre! = 1 & & chiffre! = 3 & & chiffre! = 4 & & chiffre! = 5 & & chiffre! = 7 & & chiffre! = 9)
digitalWrite(e,HIGH) ;
Conditions d’affichage segment f
Si (chiffre! = 1 & & chiffre! = 2 & & chiffre! = 3 & & chiffre! = 7)
digitalWrite(f,HIGH) ;
Si (chiffre! = 0 & & chiffre! = 1 & & chiffre! = 7)
digitalWrite(g,HIGH) ; }
void turnOff() {}
digitalWrite(a,LOW) ;
digitalWrite(b,LOW) ;
digitalWrite(c,LOW) ;
digitalWrite(d,LOW) ;
digitalWrite(e,LOW) ;
digitalWrite(f,LOW) ;
digitalWrite(g,LOW) ; }
void loop() {LDRValue = analogRead(LDR) ;
int i ;
pour (i = 9; J’ai > 0; i--) {displayDigit(i) ; delay(1000) ; turnOff() ;
Si (j’ai < = 3)
digitalWrite(tril,LOW) ;
d’autre digitalWrite(tril,HIGH) ;
Serial.println(LDRValue) ;
Si (LDRValue < 500)
{
digitalWrite(tril,HIGH) ; } } }
Ouvert le Serial Monitor pour vérifier les valeurs de la LDR, pour définir le seuil qui correspond à votre environnement, ajuster "si (LDRValue < 500) » à votre seuil.