This is my first post regarding issue with my code, for counter 0, 100.
two dogit working fine but third digit doesn't lit. Is there any body can help me.
Kind Regards
Here is my code
//Prepare binary array for all 7 segment to turn on 7 segment at position of a,b,c,d,e,f,g
char digit[10] = { 0b0111111, 0b0000110, 0b1011011, 0b1001111, 0b1100110, 0b1101101, 0b1111101, 0b0000111, 0b1111111, 0b1101111 };
int digit1 = 12, digit2 = 3, digit3 = 2; // initialize individual digit to controll each segment
char a = 0, b = 0, c = 0;
void setup() {
for (int i = 2; i < 13; i++)
pinMode(i, OUTPUT); // declare 0-9 th pin as output
digitalWrite(digit1, LOW);
digitalWrite(digit2, LOW);
digitalWrite(digit3, LOW);
}
void loop() {
a++;
if (a > 9){ a = 0;b++;}
if (b > 9) { b = 0; c++;}
if (c > 9) c = 0;
for(int k=0; k<10; k++){
digitalWrite(digit1, LOW);
digitalWrite(digit2, HIGH);
digitalWrite(digit3, HIGH);
senddata(a);
delay(5);
digitalWrite(digit1, HIGH);
digitalWrite(digit2, LOW);
digitalWrite(digit3, HIGH);
senddata(b);
delay(5);
digitalWrite(digit1, HIGH);
digitalWrite(digit2, HIGH);
digitalWrite(digit3, LOW);
senddata(c);
delay(5);
}
}
void senddata(unsigned char y) {
unsigned char t;
t= digit[y];
boolean x;
for(int j=0; j<8; j++)
{
x= bitRead(t,j);
digitalWrite(j+4,x);
}
}
Exchange pins 2 and 12 or 3 and 12, run your sketch and describe the results. I assume the 3x7seg has an external power supply (24 segs x 15mA/seg = 360mA).
Thank you so much for your reply, I exchange the wire, now third one lit, but second one never lit, I think there is no enough power, I am going to add transister on digit pins and power it from external power supply.