0

i've got a seven-segment-display on my arduino-nano and want to write some numbers on it. The problem is that HIGH and LOW seems to be reversed. If the output should be

0

it displays

-

I could solve this, replacing all HIGH and LOW through HIGHX and LOWX, and defining them reversed:

 #define HIGHX 0x0
 #define LOWX 0x1

but this is reversed and not a good solution...

The wiring is correct like this (just GND not connected): enter image description here

But if i connect the GND, the hole display isn't showing something anymore.

1

3 Answers 3

1

With the given schematic both your logic for segments and digits should be active high, so it looks like you made a mistake. Especially because you say it doesn't work anymore when you connect ground. Check that you have the right transistor and that it's connected correctly: Emitter should go to ground, collector to the display's common cathode. (Check that your displays are common cathode!)

It's not a good idea to define some version of high as low, that's only confusing. Instead name the signals:

#define DISPLAY_SEGMENT_ON HIGH
#define DISPLAY_DIGIT_ON HIGH

The image can be found at several places on the Internet, so I guess you didn't draw it. This is a common cathode display, and the transistors are NPN types. If your displays are common anode then the whole thing flips upside-down: The Ground rail becomes Vcc, and the NPN transistors should be PNP types. Then you will indeed have inverted logic, and you should define:

#define DISPLAY_SEGMENT_ON LOW
#define DISPLAY_DIGIT_ON LOW
0

If your display is a common anode type, the following will happen.

Suppose you put a HIGH on D12, and LOW on D2 then current will flow from D12 through the base-collector diode of Q1, through the LED and out D2 to ground.

If you now connect Gnd to ground wihout changing anything else, the current from D12 will flow through the base-emitter diode of Q1 to ground and not through the LED.

So the display is probably of the wrong type for your design.

0

reversing a boolean can be done using the ! operator. So doing something like print(!true); will print false (or 0, I'm not sure.)

And you make a wrapper or class to abstract this specific/odd behaviour.

Like:

"setLedPin(pinnr,state){digitalWrite(pinnr,!state)} //The pins are inverted, LOW is ON, HIGH is off, this piece inverts it."

You may even make a class for these segment displays and pass to your constructor if it's an inverted or "normal" one. Or even make two classes that implement the same interface, but for such a small difference, that shouldn't be necessary.

1
  • While it is technically correct, it's confusing for the human programmer. Best practice is using "positive" names/description like "DISPLAY_IS_ON" for all constant/variables. "Negative" names, like "DISPLAY_IS_NOT_ON" induce errors; you have to mentally compile what !DISPLAY_IS_NOT_ON means.
    – user31481
    Nov 6, 2017 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.