Kodenya:
int a=2;
int b=3;
int c=4;
int d=5;
int e=6;
int f=7;
int g=8;
int
number=0;
int
pin9=9;
int
pin10=10;
int
pin11=11;
int
pin12=12;
int
tens=0;
int
unit=0;
int
digit=0;
int
hundreds=0;
int
tens1=0;
int
presentvalue=0;
int
previousvalue=0;
void
setup()
{
//Serial.begin(9600);
pinMode(a,OUTPUT);
pinMode(b,OUTPUT);
pinMode(c,OUTPUT);
pinMode(d,OUTPUT);
pinMode(e,OUTPUT);
pinMode(f,OUTPUT);
pinMode(g,OUTPUT);
pinMode(pin9,OUTPUT);
pinMode(pin10,OUTPUT);
pinMode(pin11,OUTPUT);
pinMode(pin12,INPUT);
}
void
loop()
{
presentvalue=digitalRead(pin12);
if
(presentvalue!=previousvalue)
{
if (presentvalue==1)
{number=number+1;}
previousvalue=presentvalue;
}
display1();
}
void
display1()
{
hundreds=number/100;
tens1=number%100;
tens=tens1/10;
unit=tens1%10;
for (int
i=0;i<=10;i++)
{
digit=hundreds;
digitselection();
digitalWrite(pin9,HIGH);
digitalWrite(pin10,LOW);
digitalWrite(pin11,LOW);
delay(1);
digit=tens;
digitselection();
digitalWrite(pin9,LOW);
digitalWrite(pin10,HIGH);
digitalWrite(pin11,LOW);
delay(1);
digit=unit;
digitselection();
digitalWrite(pin9,LOW);
digitalWrite(pin10,LOW);
digitalWrite(pin11,HIGH);
delay(1);
}
if
(number>999) {number=0;}
}
void
zero()
{
digitalWrite(a,HIGH);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,LOW);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
}
void
one()
{
digitalWrite(a,LOW);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
}
void
two()
{
digitalWrite(c,LOW);
digitalWrite(f,LOW);
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(g,HIGH);
digitalWrite(e,HIGH);
digitalWrite(d,HIGH);
}
void
three()
{
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(g,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
}
void
four()
{
digitalWrite(a,LOW);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
}
void
five()
{
digitalWrite(e,LOW);
digitalWrite(b,LOW);
digitalWrite(a,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
}
void
six()
{
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
}
void
seven()
{
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
}
void
eight()
{
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
}
void
nine()
{
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
}
void
digitselection()
{
switch (digit)
{
case 0:
zero();
break;
case 1:
one();
break;
case 2:
two();
break;
case 3:
three();
break;
case 4:
four();
break;
case 5:
five();
break;
case 6:
six();
break;
case 7:
seven();
break;
case 8:
eight();
break;
case 9:
nine();
break;
}
}