char digit,digit1,digit2,digit3,digit4;
int sw1 = A0;///uln2003 output
int sw2 = A1;
int sw3 = A2;
int sw4 = A3;
int sw5 = A4;
// saven segment display pin connection
int da =2 ;
int db =3 ;
int dc =4 ;
int dd =5 ;
int de =6 ;
int df =7 ;
int dg =8 ;
void setup() {
Serial.begin(9600);
pinMode(da, OUTPUT);
pinMode(db, OUTPUT);
pinMode(dc, OUTPUT);
pinMode(dd, OUTPUT);
pinMode(de, OUTPUT);
pinMode(df, OUTPUT);
pinMode(dg, OUTPUT);
pinMode(sw1, INPUT_PULLUP);
pinMode(sw2, INPUT_PULLUP);
pinMode(sw3, INPUT_PULLUP);
pinMode(sw4, INPUT_PULLUP);
pinMode(sw5, INPUT_PULLUP);
digit1=0;
mux();
}
void loop() {
if(digitalRead(sw1) == LOW&&digitalRead(sw2) == LOW&&digitalRead(sw3) == LOW&&digitalRead(sw4) == LOW&&digitalRead(sw5) == LOW){
digit1=5;
mux();
}
if(digitalRead(sw1) == HIGH&&digitalRead(sw2) == HIGH&&digitalRead(sw3) == HIGH&&digitalRead(sw4) == HIGH&&digitalRead(sw5) == HIGH){
digit1=0;
mux();
}
if(digitalRead(sw1) == LOW&&digitalRead(sw2) == HIGH&&digitalRead(sw3) == HIGH&&digitalRead(sw4) == HIGH&&digitalRead(sw5) == HIGH){
digit1=1;
mux();
}
if(digitalRead(sw1) == LOW&&digitalRead(sw2) == LOW&&digitalRead(sw3) == HIGH&&digitalRead(sw4) == HIGH&&digitalRead(sw5) == HIGH){
digit1=2;
mux();
}
if(digitalRead(sw1) == LOW&&digitalRead(sw2) == LOW&&digitalRead(sw3) == LOW&&digitalRead(sw4) == HIGH&&digitalRead(sw5) == HIGH){
digit1=3;
mux();
}
if(digitalRead(sw1) == LOW&&digitalRead(sw2) == LOW&&digitalRead(sw3) == LOW&&digitalRead(sw4) == LOW&&digitalRead(sw5) == HIGH){
digit1=4;
mux();
}
}
void comp(){
if(digit==0){dzero();}
if(digit==1){done();}
if(digit==2){dtwo();}
if(digit==3){dthree();}
if(digit==4){dfour();}
if(digit==5){dfive();}
if(digit==6){dsix();}
if(digit==7){dseven();}
if(digit==8){deight();}
if(digit==9){dnine();}
}
void mux()
{
digit=digit1;
comp();
}
void done(){
digitalWrite(db, LOW); // turn the LED off by making the voltage LOW
digitalWrite(dc, LOW); // turn the LED off by making the voltage LOW
digitalWrite(da, HIGH); // turn the LED off by making the voltage LOW
digitalWrite(dd, HIGH); // turn the LED off by making the voltage LOW
digitalWrite(de, HIGH); // turn the LED off by making the voltage LOW
digitalWrite(df, HIGH); // turn the LED off by making the voltage LOW
digitalWrite(dg, HIGH); // turn the LED off by making the voltage LOW
}
void dtwo(){
digitalWrite(da, LOW); // turn the LED off by making the voltage LOW
digitalWrite(db, LOW); // turn the LED off by making the voltage LOW
digitalWrite(de, LOW); // turn the LED off by making the voltage LOW
digitalWrite(dd, LOW); // turn the LED off by making the voltage LOW
digitalWrite(dg, LOW); // turn the LED off by making the voltage LOW
digitalWrite(dc, HIGH); // turn the LED off by making the voltage LOW
digitalWrite(df, HIGH); // turn the LED off by making the voltage LOW
}
void dthree(){
digitalWrite(da, LOW); // turn the LED off by making the voltage LOW
digitalWrite(db, LOW); // turn the LED off by making the voltage LOW
digitalWrite(dc, LOW); // turn the LED off by making the voltage LOW
digitalWrite(dd, LOW); // turn the LED off by making the voltage LOW
digitalWrite(dg, LOW); // turn the LED off by making the voltage LOW
digitalWrite(de, HIGH); // turn the LED off by making the voltage LOW
digitalWrite(df, HIGH); // turn the LED off by making the voltage LOW
}
void dfour(){
digitalWrite(db, LOW); // turn the LED off by making the voltage LOW
digitalWrite(dc, LOW); // turn the LED off by making the voltage LOW
digitalWrite(df, LOW); // turn the LED off by making the voltage LOW
digitalWrite(dg, LOW); // turn the LED off by making the voltage LOW
digitalWrite(de, HIGH); // turn the LED off by making the voltage LOW
digitalWrite(dd, HIGH); // turn the LED off by making the voltage LOW
digitalWrite(da, HIGH); // turn the LED off by making the voltage LOW
}
void dfive(){
digitalWrite(da, LOW); // turn the LED off by making the voltage LOW
digitalWrite(dc, LOW); // turn the LED off by making the voltage LOW
digitalWrite(dd, LOW); // turn the LED off by making the voltage LOW
digitalWrite(df, LOW); // turn the LED off by making the voltage LOW
digitalWrite(dg, LOW); // turn the LED off by making the voltage LOW
digitalWrite(de, HIGH); // turn the LED off by making the voltage LOW
digitalWrite(db, HIGH); // turn the LED off by making the voltage LOW
}
void dsix(){
digitalWrite(da, LOW); // turn the LED off by making the voltage LOW
digitalWrite(dc, LOW); // turn the LED off by making the voltage LOW
digitalWrite(dd, LOW); // turn the LED off by making the voltage LOW
digitalWrite(df, LOW); // turn the LED off by making the voltage LOW
digitalWrite(dg, LOW); // turn the LED off by making the voltage LOW
digitalWrite(de, LOW); // turn the LED off by making the voltage LOW
digitalWrite(db, HIGH); // turn the LED off by making the voltage LOW
}
void dseven(){
digitalWrite(da, LOW); // turn the LED off by making the voltage LOW
digitalWrite(dc, LOW); // turn the LED off by making the voltage LOW
digitalWrite(db, LOW); // turn the LED off by making the voltage LOW
digitalWrite(df, HIGH); // turn the LED off by making the voltage LOW
digitalWrite(dg, HIGH); // turn the LED off by making the voltage LOW
digitalWrite(de, HIGH); // turn the LED off by making the voltage LOW
digitalWrite(dd, HIGH); // turn the LED off by making the voltage LOW
}
void deight(){
digitalWrite(da, LOW); // turn the LED off by making the voltage LOW
digitalWrite(dc, LOW); // turn the LED off by making the voltage LOW
digitalWrite(dd, LOW); // turn the LED off by making the voltage LOW
digitalWrite(df, LOW); // turn the LED off by making the voltage LOW
digitalWrite(dg, LOW); // turn the LED off by making the voltage LOW
digitalWrite(de, LOW); // turn the LED off by making the voltage LOW
digitalWrite(db, LOW); // turn the LED off by making the voltage LOW
}
void dnine(){
digitalWrite(da, LOW); // turn the LED off by making the voltage LOW
digitalWrite(dc, LOW); // turn the LED off by making the voltage LOW
digitalWrite(dd, LOW); // turn the LED off by making the voltage LOW
digitalWrite(df, LOW); // turn the LED off by making the voltage LOW
digitalWrite(dg, LOW); // turn the LED off by making the voltage LOW
digitalWrite(de, HIGH); // turn the LED off by making the voltage LOW
digitalWrite(db, LOW); // turn the LED off by making the voltage LOW
}
void dzero(){
digitalWrite(da, LOW); // turn the LED off by making the voltage LOW
digitalWrite(dc, LOW); // turn the LED off by making the voltage LOW
digitalWrite(dd, LOW); // turn the LED off by making the voltage LOW
digitalWrite(df, LOW); // turn the LED off by making the voltage LOW
digitalWrite(dg, HIGH); // turn the LED off by making the voltage LOW
digitalWrite(de, LOW); // turn the LED off by making the voltage LOW
digitalWrite(db, LOW); // turn the LED off by making the voltage LOW
}