I'm currently learning Arduino and could do with a bit of advice with regards to reducing the length and size of my current code.
I have done some reading online and couldn't find information about changing the way in which I trigger the segments to light (but I know there must be a better way)
I will also include a series of images of my board and an image to show the current wiring
(the wiring picture isn't very well made but in my circumstances I can't make one better)
Thanks in advance for any advice or links provided, Ewdie
I think it's relatively clear... I'm interested in a method of shortening my current code and would like advice with regards to shortening and reducing (maybe completely replacing) that area....
I'm not interested in having it done for me but links or a push in the right direction would be more than appreciated
I'm currently learning Arduino and could do with a bit of advice with regards to reducing the length and size of my current code.
I have done some reading online and couldn't find information about changing the way in which I trigger the segments to light (but I know there must be a better way)
The code originally went up to 20 but I can't fit it all in one post (due to restrictions)
I will also include a series of images of my board and an image to show the current wiring
(the wiring picture isn't very well made but in my circumstances I can't make one better)
Thanks in advance for any advice or links provided, Ewdie
I am not understanding what you want.
Do you want a counter to go from 0 to 20 only and then back again to 0?
As to your hardware, you need a resistor for each segment of your 7-segment display, so you need fourteen resistors.
There are a lot of tutorials online for Arduino with 7-segment display. I would suggest you start with one of those.
You should not be worried about the length of your code right now because there is something more important to worry about.
The way you have wired up your display is going to damage the Nano, and may already have done so.
You need 7 series resistors for the led segments, two transistors to handle the current from the display common connectors and 2 resistors for the transistor bases.
Please ask if you are interested in an explanation.
You should not be worried about the length of your code right now because there is something more important to worry about.
The way you have wired up your display is going to damage the Nano, and may already have done so.
You need 7 series resistors for the led segments, two transistors to handle the current from the display common connectors and 2 resistors for the transistor bases.
Please ask if you are interested in an explanation.
Paul
I understand the Resistors, but I don't understand the Transistors, can you explain please
An Arduino output can only source or sink a maximum of 40mA. More than that could damage it. Right now your circuit has the Arduino pins, the two that are connected to the display common pins, sourcing or sinking the current from 7 segments at once. With no series resistors, its hard to know how much that is but it is likely to be way more than 40mA.
You have a couple of choices. You could put in high value series resistors (e.g. 1K) so that the total current from 7 segments is less than 40mA. This may make the display somewhat dim. Or you can use a couple of transistors. The transistors can handle the current from 7 segments easily. Then you can use lower series resistors (e.g. 220R) for a brighter display. The transistors would be connected between the Arduino pins and the display common connectors using a resistor (e.g. 4K7). The type of transistor would depend on the type of display you have. NPN transistors for common cathode displays, PNP transistor for common anode displays.
Frankly I would not drive an LED directly from the Arduino in this manner - as was previously mentioned you risk exceeded the amount of current the Arduino can handle.
Using a multiplexer (such as the ubiquitous MAX7219) gets around this (sort of, depends on number of digits) by only turning on segments very quickly for each digit. Works like a dream.
If you think this might be an approach you could take take a look at my videos #9, #10 & #11 and you will know all you want to know about using a MAX7219 and an 7 segment display! Then you can just 'write' the number to the required digit without any fuss at all.
Yes, with PNP transistor.
Using TPIC6C595 open drain shift register vs Arduino pins would eliminate current concerns, free up Arduino pins, and also make coding easier as then just need to shift out a byte, turn on anode drive, after 3-4mS turn off anode drive, shift out a byte, turn on the next anode drive, after 3-4mS turn off anode drive, and repeat.
With 220R or 330R series resistors, the Arduino will be able to supply the current ok, as long as it it not also supplying too much else (other leds etc).
You may also need to adjust your code slightly because the transistors will logically invert the Arduino output. But then you came here for suggestions for code changes anyway! Let us know when you have the display working ok with the transistors & resistors and we can start looking at it.
CrossRoads:
Yes, with PNP transistor.
Using TPIC6C595 open drain shift register vs Arduino pins would eliminate current concerns, free up Arduino pins, and also make coding easier as then just need to shift out a byte, turn on anode drive, after 3-4mS turn off anode drive, shift out a byte, turn on the next anode drive, after 3-4mS turn off anode drive, and repeat.