3

I have a question regarding the use of SevSegShift library. I followed the example properly and tested it to see if it works. It was able to power up the seven segments and light up the whole LEDs (even the decimal) but it's not showing the output I want to show.

Based on the code below, I want to show the number 500 but it does not. Even tried sevsegshift.setChars("abcd"), no change.

This is my code:

#include <SevSegShift.h>

#define SHIFT_PIN_SHCP 6 #define SHIFT_PIN_STCP 5 #define SHIFT_PIN_DS 4

SevSegShift sevseg(SHIFT_PIN_DS, SHIFT_PIN_SHCP, SHIFT_PIN_STCP, 1, true);

void setup() { byte numDigits = 4; byte digitPins[] = {9, 10, 11, 12}; // These are the PINS of the ** Arduino ** byte segmentPins[] = {0, 1, 2, 3, 4, 5, 6, 7}; // these are the PINs of the ** Shift register ** bool resistorsOnSegments = false; // 'false' means resistors are on digit pins byte hardwareConfig = COMMON_CATHODE; // See README.md for options bool updateWithDelays = false; // Default 'false' is Recommended bool leadingZeros = false; // Use 'true' if you'd like to keep the leading zeros bool disableDecPoint = true; // Use 'true' if your decimal point doesn't exist or isn't connected

sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments, updateWithDelays, leadingZeros, disableDecPoint); sevseg.setBrightness(10); }

void loop() { sevseg.setNumber(500); //delay(1000); sevseg.refreshDisplay(); // Must run repeatedly; don't use blocking code (ex: delay()) in the loop() function or this won't work right }

This is my breadboard schematic down below.

Breadboard

(220 ohm resistors on the digit pins and the segment pins are connected to the shift register)

fireblazer10
  • 111
  • 2
  • 10

1 Answers1

4

Finally able to fix it with the help of @PeterPaulKiefer, I was able to find the problem. The problem is in the code itself (schematic is alright. No changes there) and this is the updated code.

#include <SevSegShift.h>

#define SHIFT_PIN_SHCP 6 #define SHIFT_PIN_STCP 5 #define SHIFT_PIN_DS 4

SevSegShift sevseg(SHIFT_PIN_DS, SHIFT_PIN_SHCP, SHIFT_PIN_STCP, 1, true);

void setup() { byte numDigits = 4; byte digitPins[] = {12, 11, 10, 9}; // These are the PINS of the ** Arduino ** byte segmentPins[] = {0, 1, 2, 3, 4, 5, 6, 7}; // these are the PINs of the ** Shift register ** bool resistorsOnSegments = false; // 'false' means resistors are on digit pins byte hardwareConfig = COMMON_ANODE; // See README.md for options bool updateWithDelays = false; // Default 'false' is Recommended bool leadingZeros = false; // Use 'true' if you'd like to keep the leading zeros bool disableDecPoint = false; // Use 'true' if your decimal point doesn't exist or isn't connected

sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments, updateWithDelays, leadingZeros, disableDecPoint); sevseg.setBrightness(100); }

void loop() { sevseg.setNumber(500); sevseg.refreshDisplay(); // Must run repeatedly; don't use blocking code (ex: delay()) in the loop() function or this won't work right }

What changed:

  1. Turns out my 7-segment is COMMON_ANODE so I changed my hardwareConfig
  2. Set brightness to 100 (At this point, it shows the number in reverse but with a decimal point in each digit)
  3. Set disableDecPoint to false (At this point, the display is showing but in reverse but no more decimal point) reverse
  4. To fix this, I set the digitPins[] in reverse and it now shows the proper format Correct Output

Thank you so much Peter for helping me figure out what's wrong!

Also the LED Bar I use is 4-Digit 0.36" LED, 7-segments display, common-anode. (The link is to the shop I got it from)

fireblazer10
  • 111
  • 2
  • 10