4 Digit, 7 Segment Counter Help

Hi all,

I'm trying to make a counter with a 4 digit display but I can't find any code thats well commented to get some guidance from. Most of the code I've found from googling are for clocks of timers, however I need mine to work off a switch so that whenever the switch pin goes HIGH it will count one up; this is why I'm getting stuck as I haven't found anything I can 'plug in and play.' Could someone point me in the right direction please?

Thanks in advance!

Jack

You need to start with your schematic. There are two ways of driving a 7 segment display, direct segment driving and multiplexing you need to choose what way to do it. It could be that your display dictates what method you have to use.

I was going to use a common cathode display and the multiplexing method, as it seems the best way of doing it. However, do you think there any 3rd party hardware that might do the job?

Get a MAX7219, controls up to 8 7-segment displays.
Easy to use, just write some registers, it takes care of the multiplexing for.
Needs 3 external components - 10K resistor, 0.1uF cap, 10uF cap.
$3 from tayaelectronics.com

Hi just wire up for one of the 7SegDis., then write your program to fire the one display. following that modify the routine so as to shut down theh first and fire out the detail to the next, in your case four transistors attached to 4 differing output pins then open that transistor and shutting it so as pass current to a particular 7SegDis., and then your next digit to the second transistor and display and the for the third and then for the fourth the speed of reaction is so fast that the eye does not notice the opening and shutting of the transistor or 7SegDis., and hence you wil have to all intents and purposes a constant diplay.

I have never done it but that's how I see it happening as I carried out other programming that is similar.

Hope its not double Dutch., cheers,
Chris S.

Hi CrossRoads,

Sorry, the link you sent me doesn't work on my end :confused: What is it I'm looking for? I'll google it and have a research :slight_smile: Also, what do you meant by 'write some registers?' I'm not familiar with them.

Thanks,

Jack

what do you meant by 'write some registers?' I'm not familiar with them.

That chip has some registers in them, he was saying you have to:-
'write to some registers

Read the datasheet. There are 15 addresses you can write to.
4 or 5 set up how the chip works, how many digits, etc.
Then there are 8 that are the data that is actually displayed, one for each digit.

So write to the 5 control registers in setup to setup the part, then send data to the part in loop.
I use SPI at default settings to talk to the part:
digitalWrite (ssPin, LOW); // D10
SPI.transfer(address); // D13/SCK is the clock, D11/MOSI is the serial data out
SPI.transfer(data);
digitalWrite (ssPin, HIGH);

So you might have a for:loop from 1 to 8 for your addresses, with data coming from an array when you want to update the display:

for (x=1; x<=8; x=x+1){
digitalWrite (ssPin, LOW);
SPI.transfer(x); // 1 to 8 for the data register
SPI.transfer(displayArray[x-1]); // displayArray[0] to displayArray[7]
digitalWrite (ssPin, HIGH);
}

I to would suggest that same chips CrossRoads suggest (MAX72xx chips)

Where my advice differs is that being that you are new, you may want to look into using one the available libraries to get your project up and running..

http://playground.arduino.cc/Main/MAX72XXHardware
http://playground.arduino.cc/Main/LedControl
http://playground.arduino.cc/Main/LEDMatrix

I use the LedControl library alot myself for quick and easy set-up

That being said the advice & approach given above will make you a better coder and understand the SPI protocol so it can be applied to other projects/SPI devices.. It is a 'crutch-free' approach and ultimately gives you more control instead of being pigeon holed into only being able to use the pre-made functions of a library.