I am getting error with this. It is displaying those segments which are not to be displayed, i.e., 3.141
is dark and other segments are red.
#include "SevSeg.h"
SevSeg sevseg; //Initiate a seven segment controller object
void setup() {
byte numDigits = 4;
byte digitPins[] = {2, 3, 4, 5};
byte segmentPins[] = {6, 7, 8, 9, 10, 11, 12, 13};
sevseg.begin(COMMON_ANODE, numDigits, digitPins, segmentPins);
sevseg.setBrightness(1000);
}
void loop() {
sevseg.setNumber(3141, 3);
sevseg.refreshDisplay(); // Must run repeatedly
}
-
4Are you sure you have the right type of common for your display?Majenko– Majenko2015年07月21日 12:34:56 +00:00Commented Jul 21, 2015 at 12:34
2 Answers 2
There are two main types of seven segment display:
- Common Anode
- Common Cathode
The common refers to the fact that one end of the LEDs within a digit are linked, and need to be connected to either Vcc or GND, depending on the type of the display (see below). The other end of each led (one per segment) is used to switch them on, and it is these that go to the Arduino pins, or LED controller.
Common Anode
Common Anode
The common end is connected to the Vcc line. If you wish to light a segment, then the input pin for that segment needs to be pulled LOW
.
Common Anode 4 digit seven segment display
Common Anode single digit seven segment display
Source: Four multiplexed 7-segment COMMON ANODE LED
Common Cathode
Common Cathode
The common end is connected to the GND line. If you wish to light a segment, then the input pin for that segment needs to be pulled HIGH
.
Common Cathode single digit seven segment display
It sounds as if you have the logic inverted, so the wrong segments are lit, when they should be dark, and vice versa.
Either that, or you need to invert the logic in your code, and for example if you are currently pulling a pin LOW
to light up a segment, then you need to change your code to pull the pin HIGH
.
Image sources:
You could try the following:
#include "SevSeg.h"
SevSeg sevseg; //Initiate a seven segment controller object
void setup() {
byte numDigits = 4;
byte digitPins[] = {2, 3, 4, 5};
byte segmentPins[] = {6, 7, 8, 9, 10, 11, 12, 13};
sevseg.begin(COMMON_CATHODE, numDigits, digitPins, segmentPins);
sevseg.setBrightness(1000);
}
void loop() {
sevseg.setNumber(3141, 3);
sevseg.refreshDisplay(); // Must run repeatedly
}