Hi all,
I just started learning about arduino recently and I am currently trying to build a ten digit count down timer (in seconds)
I ran into a little bit of trouble and I am hoping someone here can give me some guidance..
Basically the count down timer is working, but it is counting down too fast. Only the 8th display (counting from left to right, so the 'hundredth' digit) is counting in seconds. The last two are counting down in milliseconds. I tried changing the count down speed, it works, however all the displays would blink instead of staying visible. I hope I am making sense.
I am using 10 seven segment display, 74hc595 shift registers, CD4511 decoder, bunch of 1k resistors and transistors.
I am using arduino leonardo if that helps.
This is my coding.
unsigned long number=1922222222, i, x=1;
void setup(){
pinMode(2, OUTPUT);//Latch
pinMode(3, OUTPUT);//Clock
pinMode(4, OUTPUT);//Data
digitalWrite(2, LOW);
Serial.begin(115200);
}
void loop(){
sevenseg(number);
number= number + x;
if (number>0)
x= - 1;
}
void sevenseg(long input_number){
byte ones, tens, hundreds, thousands, tentho, huntho, million, tenmillion, hunmillion, thomillion;
ones = byte((input_number/1)%10);
ones = (ones<<4);
tens = byte((input_number/10)%10);
tens = (tens<<4);
hundreds = byte((input_number/100)%10);
hundreds = (hundreds<<4);
thousands = byte((input_number/1000)%10);
thousands = (thousands<<4);
tentho = byte((input_number/10000)%10);
tentho = (tentho<<4);
huntho = byte((input_number/100000)%10);
huntho = (huntho<<4);
million = byte((input_number/1000000)%10);
million = (million<<4)+8;
tenmillion = byte((input_number/10000000)%10);
tenmillion = (tenmillion<<4)+4;
hunmillion = byte((input_number/100000000)%10);
hunmillion = (hunmillion<<4)+2;
thomillion = byte((input_number/1000000000)%10);
thomillion = (thomillion<<4)+1;
Serial.print(thomillion);
Serial.print(" ");
Serial.print(hunmillion);
Serial.print(" ");
Serial.print(tenmillion);
Serial.print(" ");
Serial.print(million);
Serial.print(" ");
Serial.print(huntho);
Serial.print(" ");
Serial.print(tentho);
Serial.print(" ");
Serial.print(thousands);
Serial.print(" ");
Serial.print(hundreds);
Serial.print(" ");
Serial.print(tens);
Serial.print(" ");
Serial.print(ones);
Serial.println(" ");
for ( i = 0; i < 100; i++)
if(input_number>=1000000000){
digitalWrite(2, LOW);
shiftOut(4, 3,MSBFIRST, thomillion);//(datapin, clockpin, data)
digitalWrite(2, HIGH);
}
if(input_number>=100000000){
digitalWrite(2, LOW);
shiftOut(4, 3,MSBFIRST, hunmillion);//(datapin, clockpin, data)
digitalWrite(2, HIGH);
}
if(input_number>=10000000){
digitalWrite(2, LOW);
shiftOut(4, 3,MSBFIRST, tenmillion);//(datapin, clockpin, data)
digitalWrite(2, HIGH);
}
if(input_number>=1000000){
digitalWrite(2, LOW);
shiftOut(4, 3,MSBFIRST, million);//(datapin, clockpin, data)
digitalWrite(2, HIGH);
}
if(input_number>=100000){
digitalWrite(2, LOW);
shiftOut(4, 3,MSBFIRST, huntho);//(datapin, clockpin, data)
digitalWrite(2, HIGH);
}
if(input_number>=10000){
digitalWrite(2, LOW);
shiftOut(4, 3,MSBFIRST, tentho);//(datapin, clockpin, data)
digitalWrite(2, HIGH);
}
if(input_number>=1000){
digitalWrite(2, LOW);
shiftOut(4, 3,MSBFIRST, thousands);//(datapin, clockpin, data)
digitalWrite(2, HIGH);
}
if(input_number>=100){
digitalWrite(2, LOW);
shiftOut(4, 3,MSBFIRST, hundreds);//(datapin, clockpin, data)
digitalWrite(2, HIGH);
}
if(input_number>=10){
digitalWrite(2, LOW);
shiftOut(4, 3,MSBFIRST, tens);//(datapin, clockpin, data)
digitalWrite(2, HIGH);
}
if(input_number>=1){
digitalWrite(2, LOW);
shiftOut(4, 3,MSBFIRST, ones);//(datapin, clockpin, data)
digitalWrite(2, HIGH);
}
digitalWrite(2, LOW);
}
I can change the value in [for ( i = 0; i < 100; i++)], and that would slow the timer down, but the displays would blink as mentioned above.
Any help would be greatly appreciated! Thank you