Ce n'est pas un poll !
Bonjour, moi et un ami essayons de faire un compteur qui compte les appuis sur un bouton avec un afficheur 7 segments.
Avec plusieurs essais sans succès, nous n'y arrivons toujours pas.
premier essai (AC) :
//compteur avec un afficheur à LED 7 segment AC
int valeur = 0;
int boutton = 2;
int rien = 53 ;
int zero[] = {12, 11, 10, 6, 7, 8}; // chiffre 0
int un[] = {10, 8}; // chiffre 1
int deux[] = {6, 7, 13, 11, 10}; // chiffre 2
int trois[] = {13, 11, 10, 8, 7}; // chiffre 3
int quatre[] = {13, 12, 10, 8}; // chifre 4
int cinq[] = {13, 12, 11, 8, 7}; // chiffre 5
int six[] = {13, 12, 11, 6, 7, 8}; // chiffre 6
int sept[] = {8, 10, 11}; // chiffre 7
int huit[] = {12, 11, 10, 13, 6, 7, 8}; // chiffre 8
int neuf[] = {12, 11, 10, 13, 8, 7}; // chiffre 9
void setup() {
pinMode(rien,OUTPUT);
pinMode(zero,OUTPUT);
pinMode(un,OUTPUT);
pinMode(deux,OUTPUT);
pinMode(trois,OUTPUT);
pinMode(cinq,OUTPUT);
pinMode(six,OUTPUT);
pinMode(sept,OUTPUT);
pinMode(huit,OUTPUT);
pinMode(neuf,OUTPUT);
pinMode(boutton,INPUT);
pinMode(rien,OUTPUT);
pinMode(zero,OUTPUT);
pinMode(un,OUTPUT);
}
void loop() {
valeur = digitalRead(boutton);
// rien
digitalWrite(rien,LOW);
delay(100);
//zéro
while(valeur == HIGH){
delay(100);
if(valeur == LOW){
digitalWrite(un,HIGH);
digitalWrite(deux,HIGH);
digitalWrite(trois,HIGH);
digitalWrite(cinq,HIGH);
digitalWrite(six,HIGH);
digitalWrite(sept,HIGH);
digitalWrite(huit,HIGH);
}}
delay(100);
// un
while(valeur == HIGH){
digitalWrite(un,HIGH);
digitalWrite(deux,HIGH);
digitalWrite(trois,LOW);
digitalWrite(cinq,LOW);
digitalWrite(six,HIGH);
digitalWrite(sept,HIGH);
digitalWrite(huit,HIGH);
delay(100);
if(valeur == LOW){
digitalWrite(un,HIGH);
digitalWrite(deux,HIGH);
digitalWrite(trois,LOW);
digitalWrite(cinq,LOW);
digitalWrite(six,HIGH);
digitalWrite(sept,HIGH);
digitalWrite(huit,HIGH);
}}
// deux
while(valeur == HIGH){
digitalWrite(un,LOW);
digitalWrite(deux,LOW);
digitalWrite(trois,HIGH);
digitalWrite(cinq,LOW);
digitalWrite(six,LOW);
digitalWrite(sept,HIGH);
digitalWrite(huit,LOW);
delay(100);
if(valeur == LOW){
digitalWrite(un,LOW);
digitalWrite(deux,LOW);
digitalWrite(trois,HIGH);
digitalWrite(cinq,LOW);
digitalWrite(six,LOW);
digitalWrite(sept,HIGH);
digitalWrite(huit,LOW);
}}
// trois
while(valeur == HIGH){
digitalWrite(un,HIGH);
digitalWrite(deux,LOW);
digitalWrite(trois,LOW);
digitalWrite(cinq,LOW);
digitalWrite(six,LOW);
digitalWrite(sept,HIGH);
digitalWrite(huit,LOW);
delay(100);
if(valeur == LOW){
digitalWrite(un,HIGH);
digitalWrite(deux,LOW);
digitalWrite(trois,LOW);
digitalWrite(cinq,LOW);
digitalWrite(six,LOW);
digitalWrite(sept,HIGH);
digitalWrite(huit,LOW);
}}}
deuxième essai (CC) :
int zero[] = {12, 11, 10, 6, 7, 8}; // chiffre 0
int un[] = {10, 8}; // chiffre 1
int deux[] = {6, 7, 13, 11, 10}; // chiffre 2
int trois[] = {13, 11, 10, 8, 7}; // chiffre 3
int quatre[] = {13, 12, 10, 8}; // chifre 4
int cinq[] = {13, 12, 11, 8, 7}; // chiffre 5
int six[] = {13, 12, 11, 6, 7, 8}; // chiffre 6
int sept[] = {8, 10, 11}; // chiffre 7
int huit[] = {12, 11, 10, 13, 6, 7, 8}; // chiffre 8
int neuf[] = {12, 11, 10, 13, 8, 7}; // chiffre 9
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int e = 0;
int f = 0;
int g = 0;
int h = 0;
int i = 0;
int boutton = 2;
int bouttonstate = a;
void setup() {
for (a; a<6; a++) {
pinMode(zero[i], OUTPUT);
}
for (b; b<2; b++) {
pinMode(un[i], OUTPUT);
}
for (c; c<5; c++) {
pinMode(deux[i], OUTPUT);
}
for (d; d<5; d++) {
pinMode(trois[i], OUTPUT);
}
for (e; e<4; e++) {
pinMode(quatre[i], OUTPUT);
}
for (f; f<4; f++) {
pinMode(cinq[i], OUTPUT);
}
for (g; g<6; g++) {
pinMode(six[i], OUTPUT);
}
for (h; h<3; h++) {
pinMode(sept[i], OUTPUT);
}
for (i=0; i<7; i++) {
pinMode(huit[i], OUTPUT);
}
for (i; i<5; i++) {
pinMode(neuf[i], OUTPUT);
}
pinMode (boutton, INPUT);
}
void loop() {
bouttonstate = digitalRead(boutton);
for (a; a<6; a++) {
digitalWrite(zero[i], HIGH);
}
//
if (bouttonstate == HIGH) {
for (a; a<6; a++) {
digitalWrite(zero[i], LOW);
}
for (b; b<2; b++) {
digitalWrite(un[i], HIGH);
}
//
}
if (bouttonstate == HIGH) {
for (b; b<2; b++) {
digitalWrite(un[i], LOW);
}
for (c; c<5; c++) {
digitalWrite(deux[i], HIGH);
}
//
}
if (bouttonstate == HIGH) {
for (d; d<5; d++) {
digitalWrite(deux[i], LOW);
}
for (e; e<5; e++) {
digitalWrite(trois[i], HIGH);
}
//
}}
troisième essai (CC) :
int zero[] = {12, 11, 10, 6, 7, 8}; // chiffre 0
int un[] = {10, 8}; // chiffre 1
int deux[] = {6, 7, 13, 11, 10}; // chiffre 2
int trois[] = {13, 11, 10, 8, 7}; // chiffre 3
int quatre[] = {13, 12, 10, 8}; // chifre 4
int cinq[] = {13, 12, 11, 8, 7}; // chiffre 5
int six[] = {13, 12, 11, 6, 7, 8}; // chiffre 6
int sept[] = {8, 10, 11}; // chiffre 7
int huit[] = {12, 11, 10, 13, 6, 7, 8}; // chiffre 8
int neuf[] = {12, 11, 10, 13, 8, 7}; // chiffre 9
// bon je crois que c'est fini pour les chiffres :)
int i = 0;
int boutton = 2;
int bouttonstate = 0;
void setup() {
for (i=0; i<6; i++) {
pinMode(zero[i], OUTPUT);
}
for (i=0; i<2; i++) {
pinMode(un[i], OUTPUT);
}
for (i=0; i<5; i++) {
pinMode(deux[i], OUTPUT);
}
for (i=0; i<5; i++) {
pinMode(trois[i], OUTPUT);
}
for (i=0; i<4; i++) {
pinMode(quatre[i], OUTPUT);
}
for (i=0; i<4; i++) {
pinMode(cinq[i], OUTPUT);
}
for (i=0; i<6; i++) {
pinMode(six[i], OUTPUT);
}
for (i=0; i<3; i++) {
pinMode(sept[i], OUTPUT);
}
for (i=0; i<7; i++) {
pinMode(huit[i], OUTPUT);
}
for (i=0; i<5; i++) {
pinMode(neuf[i], OUTPUT);
}
pinMode (boutton, INPUT);
}
void loop() {
bouttonstate = digitalRead(boutton);
for (i=0; i<6; i++) {
digitalWrite(zero[i], HIGH);
}
for (i=0; i<2; i++) {
pinMode(un[i], HIGH);
}
for (i=0; i<5; i++) {
pinMode(deux[i], HIGH);
}
for (i=0; i<5; i++) {
pinMode(trois[i], HIGH);
}
for (i=0; i<4; i++) {
pinMode(quatre[i], HIGH);
}
for (i=0; i<4; i++) {
pinMode(cinq[i], HIGH);
}
for (i=0; i<6; i++) {
pinMode(six[i], HIGH);
}
for (i=0; i<3; i++) {
pinMode(sept[i], HIGH);
}
for (i=0; i<7; i++) {
pinMode(huit[i], HIGH);
}
for (i=0; i<5; i++) {
pinMode(neuf[i], HIGH);
}
}
voilà.
Pouvez-vous nous indiquer une erreur à corriger ?
Merci; Numeross.