Hi all,
I want to make counter from 0 to 999 using 74HC595 and ULN2803 driver using a limit switch ( just like a push button pressed or not pressed ).
I have a 6 14V common Anode 7-segments each 2 display the same number
I'm using 74HC595 with ULN2803 Driver and each ULN2803 drive will be connected with separate resistors to 2 7 segments
Here's my schematic
I'm confused with the code cant make it count, I'll attach the code I found here.
int Button = 6;
int reset = 7;
int dataPin = 4; // DS pin 14 in 595
int latchPin = 5; // STCP pin 12 in 595
int clockPin = 3 ; // SHCP pin 11 in 595
int buttonState=0;
const byte pattern [10] =
{
//ABCDEFGX
0b00000011, //0
0b10011111, //1
0b00100101, //2
0b00001101, //3
0b10011001, //4
0b01001001, //5
0b01000001, //6
0b00011111, //7
0b00000001, //8
0b00011001 //9
};
void setup() {
pinMode(Button, INPUT_PULLUP);
pinMode(reset, INPUT_PULLUP);
pinMode(dataPin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
buttonState = digitalRead(Button);
if (Button == LOW) {
buttonState = buttonState +1;
if (buttonState > 999) buttonState = 0;
}
if(digitalRead (reset) == HIGH)
buttonState = 0;
for (int numberToDisplay = 0; numberToDisplay < 999; numberToDisplay++) {
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, pattern);
digitalWrite(latchPin, HIGH);
}
}
Thank you.
Well, what do you expect if you apply one code to the segments? Multiplexing is required if you want to display different patterns in each digit.
Are you kidding? Which pattern should be displayed?
Why all 1000 patterns without pausing in between?
Enable code tags first, then insert your code.
Yes the line of shiftOut command is wrong
that's why I need some help with the code, I edited the code but its still not working
Could u help me?
int Button = 6;
int reset = 7;
int dataPin = 4; // DS pin 14 in 595
int latchPin = 5; // STCP pin 12 in 595
int clockPin = 3 ; // SHCP pin 11 in 595
int num = 0;
int ones, tens, hundreds;
const byte pattern [10] =
{
//ABCDEFGX
0b00000011, //0
0b10011111, //1
0b00100101, //2
0b00001101, //3
0b10011001, //4
0b01001001, //5
0b01000001, //6
0b00011111, //7
0b00000001, //8
0b00011001 //9
};
void setup() {
pinMode(Button, INPUT_PULLUP);
pinMode(reset, INPUT_PULLUP);
pinMode(dataPin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
Button = digitalRead(6);
if (Button == HIGH) {
num = num +1;
}
if (num > 999) num = 0;
if(digitalRead (reset) == HIGH)
num = 0;
ones = num % 10;
tens = (num/10) % 10;
if (num < 10)
{
tens = 0;
hundreds = 0;
}
if (num > 10 || num <100)
hundreds = 0;
else
hundreds = num / 100;
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, pattern [ones]);
shiftOut(dataPin, clockPin, MSBFIRST, pattern [tens]);
shiftOut(dataPin, clockPin, MSBFIRST, pattern [hundreds]);
digitalWrite(latchPin, HIGH);
delay (500);
}
That doesn't make sense. What should it do?
Why that strange and erroneous handling of tens and hundreds?
Did you check the data sheet for the handling of the latch etc. signals?
I have read the datasheet of the register, And saw videos for it with arduino, that sort of registers are still new to me, I found code here for couting 0 to 999 but with a flex sensor with Analog signal,
But I cant adjust the code to work with a button
The point of ones and %10 is confusing me
I dont know it will work in Proteus,
Could u please help me with it ?
I mean &&
the problem is the simulation is not working at all, I dont know what to do
Do not cross-post. Thread locked.