Hello, i'm quite fresh with Arduinos so i wanted at first to play with some 7 segment displays, i bought a pair that shows 2 digits, anodes linked together. I've attached them all thru resistors to digital pins 2-6, and analog pins 0-4.
I've written the following code that i wanted to generate a number starting at 0 and ending up at 99, and showing it on the display, but i can't get one digit to show properly.
int j;
void loop(){
for(int i=13;i<=99;i++){
j=i%10;
digitalWrite(6,HIGH); //Using this to change cathode
digitalWrite(18,LOW); // one cathode is at pin 18 and the other on pin 6
switch(j){
case 1:{ one();break;} //the one, tho etc functios display the ceritan number
case 2:{ two();break;} // on one 7 digit display.
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;}
case 0:{ zero();break;}
default:break;
}
clear(); // clear function sets all output pins to LOW
j=(i/10)%10;
digitalWrite(6,LOW);
digitalWrite(18,HIGH);
// j=5; Here i tried using a constant, just to test it, still it didn't show up tho
switch(j){
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;}
case 0:{ zero();break;}
default: break; }
}
clear();
}
}
The number display functions each look something like this :
void one(){
digitalWrite(2,HIGH);
digitalWrite(17,HIGH);
}
I have also tried this very simple example and everything works fine.
/*
void loop(){
digitalWrite(6,LOW);
digitalWrite(18,HIGH);
one();
delay(1);
clear();
digitalWrite(6,HIGH);
digitalWrite(18,LOW);
zero();
delay(1);
clear(); }
*/
It seems i run into trouble tho when i try to display a generated two digit number and i don't understand why. The variable j seems to be allright before trying to display it ( tested it with Serial.print(j) ).
I've also attached the initialization of the pins :
int pins[11]={
-1,2,3,4,5,6,14,15,16,17,18}; //used -1 so that the vector starts at 1
void setup(){
Serial.begin(9600); // used for debugging
for(int i=1;i<=11;i++){
pinMode(pins[i], OUTPUT);
digitalWrite(pins[i],LOW);
}
digitalWrite(18,HIGH);
digitalWrite(6,HIGH);
}
Thanx in advance.