Hey guys,
so I'm trying to run a set of four 7 segment displays with an arduino. To save pins what I'm doing is using a single 7447 BCD converter, and cycling the power so that only one digit is ever on at a time, but going so fast that they look like they're all on.
Here is the code (note this is just for testing purposes as the grand scheme is for a digital clock):
byte pin0=0;
byte pin1=1;
byte pin2=2;
byte pin3=3;
byte min1pwr=4;
byte min10pwr=5;
byte hr1pwr=6;
byte hr10pwr=7;
byte var;
void setup()
{
pinMode(pin0,OUTPUT);
pinMode(pin1,OUTPUT);
pinMode(pin2,OUTPUT);
pinMode(pin3,OUTPUT);
pinMode(min1pwr,OUTPUT);
pinMode(min10pwr,OUTPUT);
pinMode(hr1pwr,OUTPUT);
pinMode(hr10pwr,OUTPUT);
}
void loop()
{
digitalWrite(hr10pwr,LOW);
var=val2;
digitalWrite(min1pwr,HIGH);
delay(1);
digitalWrite(min1pwr,LOW);
var=val5;
digitalWrite(min10pwr,HIGH);
delay(1);
digitalWrite(min10pwr,LOW);
var=val8;
digitalWrite(hr1pwr,HIGH);
delay(1);
digitalWrite(hr1pwr,LOW);
var=0;
digitalWrite(hr10pwr,HIGH);
delay(1);
if(var==0){
digitalWrite(pin0,LOW);
digitalWrite(pin1,LOW);
digitalWrite(pin2,LOW);
digitalWrite(pin3,LOW); // 0=(0,0,0,0)
}
if(var==1) {
digitalWrite(pin0,HIGH);
digitalWrite(pin1,LOW);
digitalWrite(pin2,LOW);
digitalWrite(pin3,LOW); // 1=(0,0,0,1)
}
if(var==2) {
digitalWrite(pin0,LOW);
digitalWrite(pin1,HIGH);
digitalWrite(pin2,LOW);
digitalWrite(pin3,LOW); // 2=(0,0,1,0)
}
if(var==3) {
digitalWrite(pin0,HIGH);
digitalWrite(pin1,HIGH);
digitalWrite(pin2,LOW);
digitalWrite(pin3,LOW); // 3=(0,0,1,1)
}
if(var==4) {
digitalWrite(pin0,LOW);
digitalWrite(pin1,LOW);
digitalWrite(pin2,HIGH);
digitalWrite(pin3,LOW); //4=(0,1,0,0)
}
if(var==5) {
digitalWrite(pin0,HIGH);
digitalWrite(pin1,LOW);
digitalWrite(pin2,HIGH);
digitalWrite(pin3,LOW); // 5=(0,1,0,1)
}
if(var==6) {
digitalWrite(pin0,LOW);
digitalWrite(pin1,HIGH);
digitalWrite(pin2,HIGH);
digitalWrite(pin3,LOW); //6=(0,1,1,0)
}
if(var==7) {
digitalWrite(pin0,HIGH);
digitalWrite(pin1,HIGH);
digitalWrite(pin2,HIGH);
digitalWrite(pin3,LOW); // 7=(0,1,1,1)
}
if(var==8) {
digitalWrite(pin0,LOW);
digitalWrite(pin1,LOW);
digitalWrite(pin2,LOW);
digitalWrite(pin3,HIGH); // 8=(1,0,0,0)
}
if(var==9) {
digitalWrite(pin0,HIGH);
digitalWrite(pin1,LOW);
digitalWrite(pin2,LOW);
digitalWrite(pin3,HIGH); // 9=(1,0,0,1)
}
}
Now, what's happening is that rather than showing 0852 as the code says it should, it displays 0 on each digit once, then just continually cycles on whatever number the last "var" is (in the sketch provided above, that would be 0).
As far as I can tell, that code should call for it to turn on the 4th digit, and display one number, then turn it off and turn on the 3rd digit displaying another number, and so on. However, while the power cycles properly, the displayed digits do not. interestingly enough it displays the numbers correctly if instead of saying "var=", i explicitly tell it to output the correct binary number. However, this would not be feasible for the entire code, so I was hoping for a solution similar to the one above.
Does anyone have any ideas?