Hey,
I'm trying to do counter on the 7 segment display. My problem is that the first number also shown (even bolder) on the second digit as well.
I connected the Arduino to the shift register (3 pins) and 4 pins of the Arduino for every digit (anode) and connected the shift register to the 7sigment cathodes (a-g);
The number on the photo is under 10 and should be just on the right digit.
My code is:
byte datanum[] = { B10000001, B11001111, B10010010, B10000110, B11001100, B10100100, B10100000, B10001111, B10000000, B10001100, B01111111};
int dataPin = 2; //Define which pins will be used for the Shift Register control
int latchPin = 3;
int clockPin = 4;
int shaot1Pin = 8;
int shaot0Pin = 7;
int dakot1Pin = 6;
int dakot0Pin = 5;
int time = 300;
long previousMillis = 0;
long interval = 1000;
int i = 0;
//int dd = 1000;
void setup()
{
Serial.begin(9600);
pinMode(dataPin, OUTPUT); //Configure each IO Pin
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dakot0Pin, OUTPUT);
pinMode(dakot1Pin, OUTPUT);
pinMode(shaot0Pin, OUTPUT);
pinMode(shaot1Pin, OUTPUT);
}
void loop()
{
unsigned long currentMillis = millis();
if (currentMillis - previousMillis > interval) {
// save the last time
previousMillis = currentMillis;
displaynumber1(i);
Serial.println(i);
i++;
}
else displaynumber1(i);
}
void displaynumber1(int fullnum){
int dakot0;
int dakot1;
int shaot0;
int shaot1;
if (fullnum < 10){
dakot0 = fullnum % 10;
dakot1 = 10;
shaot0 = 10;
shaot1 = 10;
}
else if (fullnum > 9 && fullnum < 100){
dakot0 = fullnum % 10;
dakot1 = (fullnum / 10) % 10;
shaot0 = 10;
shaot1 = 10;
}
else if (fullnum > 99 && fullnum < 1000){
dakot0 = fullnum % 10;
dakot1 = (fullnum / 10) % 10;
shaot0 = (fullnum / 100) % 10;
shaot1 = 10;
}
else if (fullnum > 999){
dakot0 = fullnum % 10;
dakot1 = (fullnum / 10) % 10;
shaot0 = (fullnum / 100) % 10;
shaot1 = fullnum / 1000;
}
//dakot 0
digitalWrite(dakot0Pin, HIGH);
digitalWrite(latchPin, LOW); //Pull latch LOW to start sending data
shiftOut(dataPin, clockPin, LSBFIRST, datanum[dakot0]); //Send the data
delayMicroseconds(time);
digitalWrite(latchPin, HIGH); //Pull latch HIGH to stop sending data
digitalWrite(dakot0Pin, LOW);
//delayMicroseconds(dd);
//dakot 1
digitalWrite(dakot1Pin, HIGH);
digitalWrite(latchPin, LOW); //Pull latch LOW to start sending data
shiftOut(dataPin, clockPin, LSBFIRST, datanum[dakot1]); //Send the data
//delayMicroseconds(time);
digitalWrite(latchPin, HIGH); //Pull latch HIGH to stop sending data
digitalWrite(dakot1Pin, LOW);
//delayMicroseconds(dd);
////shaot 0
//digitalWrite(shaot0Pin, HIGH);
//digitalWrite(latchPin, LOW); //Pull latch LOW to start sending data
//shiftOut(dataPin, clockPin, LSBFIRST, datanum[shaot0]); //Send the data
//delayMicroseconds(time);
//digitalWrite(latchPin, HIGH); //Pull latch HIGH to stop sending data
//digitalWrite(shaot0Pin, LOW);
////delayMicroseconds(dd);
////shaot 1
//digitalWrite(shaot1Pin, HIGH);
//digitalWrite(latchPin, LOW); //Pull latch LOW to start sending data
//shiftOut(dataPin, clockPin, LSBFIRST, datanum[shaot1]); //Send the data
//delayMicroseconds(time);
//digitalWrite(latchPin, HIGH); //Pull latch HIGH to stop sending data
//digitalWrite(shaot1Pin, LOW);
////delayMicroseconds(dd);
}
I tried to play with the delays and with the code, but I have not solution.
Anybody?
Thanks.
