Afficheur 7 segment de 0 à 99
int a=0;
void setup() {
for(int x=0; x < 14; x++)
{
pinMode(x, OUTPUT);
}
}
void chiffre_0a9()
{
digitalWrite(0, HIGH); // chiffre 0
digitalWrite(1, HIGH);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, LOW);
delay(1000);
digitalWrite(0, LOW); // chiffre 1
digitalWrite(1, LOW);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
delay(1000);
digitalWrite(0, HIGH); //chiffre 2
digitalWrite(1, HIGH);
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
digitalWrite(6, HIGH);
delay(1000);
digitalWrite(0, LOW); //chiffre 3
digitalWrite(1, HIGH);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
digitalWrite(6, HIGH);
delay(1000);
digitalWrite(0, LOW); //chiffre 4
digitalWrite(1, LOW);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
delay(1000);
digitalWrite(0, LOW); //chiffre 5
digitalWrite(1, HIGH);
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
delay(1000);
digitalWrite(0, HIGH); //chiffre 6
digitalWrite(1, HIGH);
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
delay(1000);
digitalWrite(0, LOW); //chiffre 7
digitalWrite(1, LOW);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
delay(1000);
digitalWrite(0, HIGH); //chiffre 8
digitalWrite(1, HIGH);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
delay(1000);
digitalWrite(0, LOW); //chiffre 9
digitalWrite(1, HIGH);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
delay(1000);
a++;
}
void chiffre10()
{
digitalWrite(7, HIGH); //chiffre 10
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, HIGH);
}
void chiffre20()
{
digitalWrite(7, LOW); //chiffre 20
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
}
void chiffre30()
{
digitalWrite(7, HIGH); //chiffre 30
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
}
void chiffre40()
{
digitalWrite(7, HIGH); //chiffre 40
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, LOW);
digitalWrite(13, HIGH);
}
void chiffre50()
{
digitalWrite(7, HIGH); //chiffre 50
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
}
void chiffre60()
{
digitalWrite(7, HIGH); //chiffre 60
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
}
void chiffre70()
{
digitalWrite(7, HIGH); //chiffre 70
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
}
void chiffre80()
{
digitalWrite(7, HIGH); //chiffre 80
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
}
void chiffre90()
{
digitalWrite(7, HIGH); //chiffre 90
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
}
void loop()
{
if(a <=9)
{
chiffre_0a9();
}
if(a==1)
{
chiffre10();
}
if(a==2)
{
chiffre20();
}
if(a==3)
{
chiffre30();
}
if(a==4)
{
chiffre40();
}
if(a==5)
{
chiffre50();
}
if(a==6)
{
chiffre60();
}
if(a==7)
{
chiffre70();
}
if(a==8)
{
chiffre80();
}
if(a==9)
{
chiffre90();
}
if(a >=10)
{
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
digitalWrite(0, LOW);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
}
}
Explication: Ce programme permet de faire un compteur de 0 à 99. Attention avec l'Arduino Uno enlevez le fil du pin 0 puis remettez le après le téléversement du programme sinon il vous met des erreurs. Le programme ne se réinitialise pas après avoir atteind 99.