7 digit countdown

im trying to make a simple countdown on a 4 digit 7 segment display that counts down from 31 to 0, and im also using the sevseg library. however when i upload my code, it only lights up one segment from each digit and just cycles through them.


int one= D5;
int two= D6;
//int A= D7;
//int B= D8;
//int C= D4;
//int D= D3;
//int E= D2;
//int F= D1;
//int G= D0;

#include "SevSeg.h"

SevSeg sevseg;

void setup() {
  // put your setup code here, to run once:

pinMode(one, OUTPUT);
pinMode(two, OUTPUT);
//pinMode(A, OUTPUT);
//pinMode(B, OUTPUT);
//pinMode(C, OUTPUT);
//pinMode(D, OUTPUT);
//pinMode(E, OUTPUT);
//pinMode(F, OUTPUT);
//pinMode(G, OUTPUT);

byte numDigits= 2;
 byte digitPins[] = {D5, D6};
byte segmentPins[] = {D7,D8,D4,D3,D2,D1,D0};
byte hardwareConfig = COMMON_CATHODE;
bool updateWithDelays = false;
bool leadingZeros = false;
bool disableDecPoint = true;

sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins,updateWithDelays, leadingZeros, disableDecPoint);

}

void loop() {
  // put your main code here, to run repeatedly:
  //sevseg.refreshDisplay();
  //sevseg.setNumber(31,0);
  for(int  cd=31; cd>=0; cd--)
  {
    
  sevseg.setNumber(cd, 0);
  sevseg.refreshDisplay();
    delay(1000);
    sevseg.refreshDisplay();
    delay(1000);
    sevseg.refreshDisplay();
    delay(1000);
    sevseg.refreshDisplay();
    delay(1000);
    sevseg.refreshDisplay();
    delay(1000);
    sevseg.refreshDisplay();
    delay(1000);
  }

sevseg.blank();


}

is there any way to fix this or do i try a different approach?

Which Arduino are you using? With many of them, D1 and D0 are reserved for serial communications and program upload.

The segment pins are commented out :thinking: .

Edit, the library must look after this.

Start with an example in the library, and make sure that works, before making mistakes.

Always show us a good schematic of your proposed circuit.
Show us good images of your ‘actual’ wiring.
Give links to components

i should have mentioned that i am using an ESP8266 from a plusivo kit, my bad.

Let’s check your schematic.

Without checking because instinct... I would move digitPins and segmentPins a few lines up and make them global.

Also sevseg.refreshDisplay(); might need to be called as often as possible... delay() does not help here. Please take a look at the example "Blink without delay".

not needed, they used once on lib init

Refreshing the display

sevseg.refreshDisplay();

Your program must run the refreshDisplay() function repeatedly to display the number. Warning: Any calls to delay() will interfere with the display. Any delays introduced by other functions will produce undesirable effects on the display. If you need help getting away from delay() statements,

#include "SevSeg.h"

SevSeg sevseg;

void setup() {
  byte numDigits = 2;
  byte digitPins[] = {D5, D6};
  byte segmentPins[] = {D7, D8, D4, D3, D2, D1, D0};
  byte hardwareConfig = COMMON_CATHODE;
  bool updateWithDelays = false;
  bool leadingZeros = false;
  bool disableDecPoint = true;
  sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, updateWithDelays, leadingZeros, disableDecPoint);
}

void loop() {
  static byte count = 31;
  static uint32_t oldTime = millis();
  sevseg.refreshDisplay();
  if (millis() - oldTime > 6000) {
    sevseg.setNumber(cd, 0);
    oldTime += 6000;
  }
}