4 Digit LED 7 segment display low brightness when interfaced with ESP32 Wroom

Hi

I tried to build a UV Exposure box using an ESP 32 Module and a 4 digit LED Display Common Cathode and a Rotary Encoder. The timer works perfectly, the relay turns on and off perfectly, but when it comes to the display brightness, the first Digit is really very bright and the other three digits are barely glowing. Pictures attached for reference as well as the code

Can someone tell me what is wrong with the code.

I found this code on the internet and it was for an Arduino board, all i did was use the ESP 32 , change the pin assignments and it works...!! but again the display is not bright.

i am new to coding and after 5 days of breaking my head i still cant figure out where the problem is.

Please help

final_UV_code.ino (11.5 KB)

This section of the code looks ‘wrong’ to me

// Code ------------------------------------
void updateSegments(uint8_t val)
// update the segments with the value specified
{
  for (uint8_t j = 0; j < ARRAY_SIZE(digitPin); j++)
    digitalWrite(digitPin[j], DIGIT_OFF);
  for (uint8_t i = 0; i < ARRAY_SIZE(segmentPin); i++)
  {
    digitalWrite(segmentPin[i], (val & 1 ? SEGMENT_ON : SEGMENT_OFF));
    val >>= 1;
  }
}

Seems like the first { should go at the end of the first for line, instead of before it.
Or maybe a set of { } are missing altogether:

void updateSegments(uint8_t val){
// update the segments with the value specified
  for (uint8_t j = 0; j < ARRAY_SIZE(digitPin); j++) {
    digitalWrite(digitPin[j], DIGIT_OFF);
    for (uint8_t i = 0; i < ARRAY_SIZE(segmentPin); i++)
    {
      digitalWrite(segmentPin[i], (val & 1 ? SEGMENT_ON : SEGMENT_OFF));
      val >>= 1;
    }
  }
}

And then there is no timing I see to give each digit, or each segment, the same on time, so after the last update, there is a bit of a break while other stuff happens, so the one digit gets the benefit of having the outputs static while other stuff happens, so it looks brighter than the rest.

This line here, looks to be missing a ) after PRINTS (" Pause";

      // Check if pausing


      if (SW.read() == MD_KeySwitch::KS_PRESS)
      {
        PRINTS(" Pause";
               state = S_PAUSE;
      }


      if (SW.read() == MD_KeySwitch::KS_LONGPRESS)
      {
        PRINTS(" Stop");
        state = S_END;
      }
      break;

Awful lot of blank lines in the code, way more than needed, IMO.

In this section, is the break; right at start of switch (x) going to mess things up?
I see another at the end where you'd expect to see one as the fall-thru action if there were no other matches. At the beginning seems odd

    case S_PAUSE:

      PRINTS("\nS_PAUSE");
      inMessage = true;
      displayMessage("pause", 50);

      {
        digitalWrite(OUTPUT_PIN, LOW);
        uint8_t x = SW.read();
        switch (x)
        {
            break;

          case MD_KeySwitch::KS_PRESS:
            PRINTS(" Restart");
            timeStart = millis();   // approximate, but we have paused so accurate time is out the window
            inMessage = false;
            digitalWrite(OUTPUT_PIN, HIGH);
            state = S_RUNNING;
            break;

          case MD_KeySwitch::KS_LONGPRESS:
            PRINTS(" Stop");
            inMessage = false;
            state = S_END;
            break;
        }
      }
      break;

CrossRoads:
This section of the code looks ‘wrong’ to me

// Code ------------------------------------

void updateSegments(uint8_t val)
// update the segments with the value specified
{
 for (uint8_t j = 0; j < ARRAY_SIZE(digitPin); j++)
   digitalWrite(digitPin[j], DIGIT_OFF);
 for (uint8_t i = 0; i < ARRAY_SIZE(segmentPin); i++)
 {
   digitalWrite(segmentPin[i], (val & 1 ? SEGMENT_ON : SEGMENT_OFF));
   val >>= 1;
 }
}



Seems like the first { should go at the end of the first for line, instead of before it.
Or maybe a set of { } are missing altogether:


void updateSegments(uint8_t val){
// update the segments with the value specified
 for (uint8_t j = 0; j < ARRAY_SIZE(digitPin); j++) {
   digitalWrite(digitPin[j], DIGIT_OFF);
   for (uint8_t i = 0; i < ARRAY_SIZE(segmentPin); i++)
   {
     digitalWrite(segmentPin[i], (val & 1 ? SEGMENT_ON : SEGMENT_OFF));
     val >>= 1;
   }
 }
}




I tried this but, it turned the whole display off. completely OFF

CrossRoads:
In this section, is the break; right at start of switch (x) going to mess things up?
I see another at the end where you'd expect to see one as the fall-thru action if there were no other matches. At the beginning seems odd

    case S_PAUSE:

PRINTS("\nS_PAUSE");
      inMessage = true;
      displayMessage("pause", 50);

{
        digitalWrite(OUTPUT_PIN, LOW);
        uint8_t x = SW.read();
        switch (x)
        {
            break;

case MD_KeySwitch::KS_PRESS:
            PRINTS(" Restart");
            timeStart = millis();  // approximate, but we have paused so accurate time is out the window
            inMessage = false;
            digitalWrite(OUTPUT_PIN, HIGH);
            state = S_RUNNING;
            break;

case MD_KeySwitch::KS_LONGPRESS:
            PRINTS(" Stop");
            inMessage = false;
            state = S_END;
            break;
        }
      }
      break;

CrossRoads:
In this section, is the break; right at start of switch (x) going to mess things up?
I see another at the end where you'd expect to see one as the fall-thru action if there were no other matches. At the beginning seems odd

    case S_PAUSE:

PRINTS("\nS_PAUSE");
      inMessage = true;
      displayMessage("pause", 50);

{
        digitalWrite(OUTPUT_PIN, LOW);
        uint8_t x = SW.read();
        switch (x)
        {
            break;

case MD_KeySwitch::KS_PRESS:
            PRINTS(" Restart");
            timeStart = millis();  // approximate, but we have paused so accurate time is out the window
            inMessage = false;
            digitalWrite(OUTPUT_PIN, HIGH);
            state = S_RUNNING;
            break;

case MD_KeySwitch::KS_LONGPRESS:
            PRINTS(" Stop");
            inMessage = false;
            state = S_END;
            break;
        }
      }
      break;





I really did not understand this part, or am i reading it the wrong way..what am i missing???

Hmm, okay, so I see this in other places too
for (uint8_t j = 0; j < ARRAY_SIZE(digitPin); j++)
digitalWrite(digitPin[j], DIGIT_OFF);
so maybe the ‘missing’ { } are not the problem there.

I am thinking my comment about not leaving the other digits on for equal times is still the cause of the dimness tho.
Just not sure how its being done.

switch (x)
{
break; <<< this break seems out of place, or incorrect.

CrossRoads:
Hmm, okay, so I see this in other places too
for (uint8_t j = 0; j < ARRAY_SIZE(digitPin); j++)
digitalWrite(digitPin[j], DIGIT_OFF);
so maybe the ‘missing’ { } are not the problem there.

I am thinking my comment about not leaving the other digits on for equal times is still the cause of the dimness tho.
Just not sure how its being done.

This code was used with an arduino board. i am trying to use it on the ESP32, do you think for any reason that could also be a problem ?? is this code made to work on an arduino only ???

And also when i change DIGIT_ON to HIGH and DIGIT_OFF to LOW, a few LED's glow real super bright, but the characters are jumbled or upside down. but they make no sense. But when put the way they are as in the code below, they work fine with low brightness. Just cant figure out where the brightness has been set or how it is controlled

// Digital state to turn each digit on or off during multiplexing

const uint8_t DIGIT_ON = LOW;

const uint8_t DIGIT_OFF = HIGH;

const uint8_t SEGMENT_ON = (DIGIT_ON == HIGH ? LOW : HIGH);

const uint8_t SEGMENT_OFF = (DIGIT_OFF == HIGH ? LOW : HIGH);

@CrossRoads

Thank you so much for trying

I found the problem and it is sorted and working well now. Appreciate you taking your time to reply... Thank you again