This setup will read the value of a BCD wheel and output it to a 7 segment display
/*
bcd reader and 7 segment driver
*/
//int x = 0;
int myDelay = 1000;
int counting = 0;
// the setup routine runs once when you press reset:
void setup() {
for(int i=1; i<8; i++){
pinMode(i, OUTPUT);
digitalWrite(i, LOW);
}
for(int i=8; i<13; i++){
pinMode(i, INPUT);
}
}
void ledDispDriver(int number){
for(int i=1; i<8; i++){
digitalWrite(i, LOW);
}
switch(number){
case 1:
digitalWrite(1,HIGH);
digitalWrite(2,HIGH);
break;
case 2:
digitalWrite(1,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
digitalWrite(7,HIGH);
break;
case 3:
digitalWrite(1,HIGH);
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(5,HIGH);
digitalWrite(7,HIGH);
break;
case 4:
digitalWrite(1,HIGH);
digitalWrite(2,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
break;
case 5:
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
digitalWrite(7,HIGH);
break;
case 6:
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
digitalWrite(7,HIGH);
break;
case 7:
digitalWrite(1,HIGH);
digitalWrite(2,HIGH);
digitalWrite(7,HIGH);
break;
case 8:
digitalWrite(1,HIGH);
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
digitalWrite(7,HIGH);
break;
case 9:
digitalWrite(1,HIGH);
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
digitalWrite(7,HIGH);
break;
case 0:
digitalWrite(1,HIGH);
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(6,HIGH);
digitalWrite(7,HIGH);
break;
default:
digitalWrite(1,HIGH);
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(6,HIGH);
digitalWrite(7,HIGH);
break;
}
}
int BCDdriver(){
int result = 0;
if(digitalRead(9) == HIGH){
result = 1;
}
if(digitalRead(10) == HIGH){
result = result + 2;
}
if(digitalRead(11) == HIGH){
result = result + 4;
}
if(digitalRead(12) == HIGH){
result = result + 8;
}
return result;
}
// the loop routine runs over and over again forever:
void loop() {
int x = 0;
x = BCDdriver();
ledDispDriver(x);
}