7 segment diaplay

Using the countdown timer from project hub. Can't see the numbers properly. Seems like all segments are lighting up and barely see the proper number when counting.

https://create.arduino.cc/projecthub/dmytrosavchuk/adjustable-countdown-timer-be2b3d

Here is the link which has the schematic, parts used, and code used.

Hello cgarza7
Post your current sketch, well formated, with comments and in so called code tags "</>" and a schematic, not a Fritzy diagram, to see how we can help.
Have a nice day and enjoy coding in C++.
Дайте миру шанс

Read the forum guidelines to see how to properly post code and some good information on making a good post.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Post a schematic. Hand drawn, photographed and posted is fine.

Try this


const byte segA = 2;
const byte segB = 3;
const byte segC = 4;
const byte segD = 5;
const byte segE = A0; //pin 6 is used bij display 1 for its pwm function
const byte segF = 7;
const byte segG = 8;
//int segPD = ;
const byte digit_pin[] = {6, 9, 10, 11}; // PWM Display digit pins from left to right

const byte speakerPin = 15;

#define DIGIT_ON  LOW
#define DIGIT_OFF  HIGH
#define SEGMENT_ON  HIGH
#define SEGMENT_OFF LOW
#define BRIGHTNESS 50

const byte button1 = 13;
const byte button2 = 12;
const byte button3 = 16;
const byte button4 = 17;

byte countdown_time = 60;
byte digit[4] = {0};



void setup() {
  pinMode(segA, OUTPUT);
  pinMode(segB, OUTPUT);
  pinMode(segC, OUTPUT);
  pinMode(segD, OUTPUT);
  pinMode(segE, OUTPUT);
  pinMode(segF, OUTPUT);
  pinMode(segG, OUTPUT);

  for (int i = 0; i < 4; i++) {
    pinMode(digit_pin[i], OUTPUT);
  }

  pinMode(speakerPin, OUTPUT);

  pinMode(button1, INPUT_PULLUP);
  pinMode(button2, INPUT_PULLUP);
  pinMode(button3, INPUT_PULLUP);
  pinMode(button4, INPUT_PULLUP);
}

void loop() {
  reset();
  while (!Countdown(countdown_time, 962)) {
    reset();
  }
  while (digitalRead(button2) == HIGH);
}

bool Countdown(int n, int del) {
  for (int q = n; q > 0; q--) {
    PrintNumber(q, del);
    if (digitalRead(button2) == LOW)return false;
  }
  PrintNumber(0, 0);
  playTone(1519, 1000);
  return true;
}

void playTone(int tone, int duration) {
  for (long k = 0; k < duration * 1000L; k += tone * 2) {
    digitalWrite(speakerPin, HIGH);
    delayMicroseconds(tone);
    digitalWrite(speakerPin, LOW);
    delayMicroseconds(tone);
  }
}

void SwitchDigit(byte dig) {
  for (byte i = 0; i < 4; i++)
    if (i == dig)analogWrite(digit_pin[i], BRIGHTNESS);
    else digitalWrite(digit_pin[i], DIGIT_OFF);
}

void IntToDigits(int n) {
  char i = 0;
  if (n) {
    while (i < 4) {
      if (n > 0) {
        digit[i] = n % 10;
        n /= 10;
      } else digit[i] = 10;
      i++;
    }
  }
  else {
    digit[0] = 10;
    digit[1] = 10;
    digit[2] = 10;
    digit[3] =  0;
  }
}

void PrintNumber(int n, int time) {
  IntToDigits(n);
  for (int i = 0; i <= time / 20; i++) {
    if (digitalRead(button2) == LOW) {
      return;
    }
    for (byte j = 0; j < 4; j++) {
      SwitchDigit(j);
      lightNumber(digit[j]);
      delay(5);
    }
  }
}

void reset() {
  int pressed3 = 0, pressed4 = 0;
  IntToDigits(countdown_time);
  while (digitalRead(button1) == HIGH) {
    for (int j = 0; j < 4; j++) {
      SwitchDigit(j);
      lightNumber(digit[j]);
      delay(5);
    }
    if (digitalRead(button3) == LOW) {
      if (pressed3 == 0 || pressed3 > 30) {
        if (countdown_time > 0) {
          countdown_time -= 1 ;
        }
        IntToDigits(countdown_time);
      }
      pressed3 += 1;
    }
    else if (digitalRead(button4) == LOW) {
      if (pressed4 == 0 || pressed4 > 30) {
        if (countdown_time < 9999) {
          countdown_time += 1 ;
        }
        IntToDigits(countdown_time);
      }
      pressed4 += 1;
    }
    if (digitalRead(button3) == HIGH)pressed3 = 0;
    if (digitalRead(button4) == HIGH)pressed4 = 0;
  }
}

void lightNumber(byte numberToDisplay) {
  switch (numberToDisplay) {
    case 0:
      digitalWrite(segA, SEGMENT_ON);
      digitalWrite(segB, SEGMENT_ON);
      digitalWrite(segC, SEGMENT_ON);
      digitalWrite(segD, SEGMENT_ON);
      digitalWrite(segE, SEGMENT_ON);
      digitalWrite(segF, SEGMENT_ON);
      digitalWrite(segG, SEGMENT_OFF);
      break;
    case 1:
      digitalWrite(segA, SEGMENT_OFF);
      digitalWrite(segB, SEGMENT_ON);
      digitalWrite(segC, SEGMENT_ON);
      digitalWrite(segD, SEGMENT_OFF);
      digitalWrite(segE, SEGMENT_OFF);
      digitalWrite(segF, SEGMENT_OFF);
      digitalWrite(segG, SEGMENT_OFF);
      break;
    case 2:
      digitalWrite(segA, SEGMENT_ON);
      digitalWrite(segB, SEGMENT_ON);
      digitalWrite(segC, SEGMENT_OFF);
      digitalWrite(segD, SEGMENT_ON);
      digitalWrite(segE, SEGMENT_ON);
      digitalWrite(segF, SEGMENT_OFF);
      digitalWrite(segG, SEGMENT_ON);
      break;
    case 3:
      digitalWrite(segA, SEGMENT_ON);
      digitalWrite(segB, SEGMENT_ON);
      digitalWrite(segC, SEGMENT_ON);
      digitalWrite(segD, SEGMENT_ON);
      digitalWrite(segE, SEGMENT_OFF);
      digitalWrite(segF, SEGMENT_OFF);
      digitalWrite(segG, SEGMENT_ON);
      break;
    case 4:
      digitalWrite(segA, SEGMENT_OFF);
      digitalWrite(segB, SEGMENT_ON);
      digitalWrite(segC, SEGMENT_ON);
      digitalWrite(segD, SEGMENT_OFF);
      digitalWrite(segE, SEGMENT_OFF);
      digitalWrite(segF, SEGMENT_ON);
      digitalWrite(segG, SEGMENT_ON);
      break;
    case 5:
      digitalWrite(segA, SEGMENT_ON);
      digitalWrite(segB, SEGMENT_OFF);
      digitalWrite(segC, SEGMENT_ON);
      digitalWrite(segD, SEGMENT_ON);
      digitalWrite(segE, SEGMENT_OFF);
      digitalWrite(segF, SEGMENT_ON);
      digitalWrite(segG, SEGMENT_ON);
      break;
    case 6:
      digitalWrite(segA, SEGMENT_ON);
      digitalWrite(segB, SEGMENT_OFF);
      digitalWrite(segC, SEGMENT_ON);
      digitalWrite(segD, SEGMENT_ON);
      digitalWrite(segE, SEGMENT_ON);
      digitalWrite(segF, SEGMENT_ON);
      digitalWrite(segG, SEGMENT_ON);
      break;
    case 7:
      digitalWrite(segA, SEGMENT_ON);
      digitalWrite(segB, SEGMENT_ON);
      digitalWrite(segC, SEGMENT_ON);
      digitalWrite(segD, SEGMENT_OFF);
      digitalWrite(segE, SEGMENT_OFF);
      digitalWrite(segF, SEGMENT_OFF);
      digitalWrite(segG, SEGMENT_OFF);
      break;
    case 8:
      digitalWrite(segA, SEGMENT_ON);
      digitalWrite(segB, SEGMENT_ON);
      digitalWrite(segC, SEGMENT_ON);
      digitalWrite(segD, SEGMENT_ON);
      digitalWrite(segE, SEGMENT_ON);
      digitalWrite(segF, SEGMENT_ON);
      digitalWrite(segG, SEGMENT_ON);
      break;
    case 9:
      digitalWrite(segA, SEGMENT_ON);
      digitalWrite(segB, SEGMENT_ON);
      digitalWrite(segC, SEGMENT_ON);
      digitalWrite(segD, SEGMENT_ON);
      digitalWrite(segE, SEGMENT_OFF);
      digitalWrite(segF, SEGMENT_ON);
      digitalWrite(segG, SEGMENT_ON);
      break;
    case 10:
      digitalWrite(segA, SEGMENT_OFF);
      digitalWrite(segB, SEGMENT_OFF);
      digitalWrite(segC, SEGMENT_OFF);
      digitalWrite(segD, SEGMENT_OFF);
      digitalWrite(segE, SEGMENT_OFF);
      digitalWrite(segF, SEGMENT_OFF);
      digitalWrite(segG, SEGMENT_OFF);
      break;
  }
}

I have the same problem. I tryed the new code but i still have the same result.
I am trying this with a uno but it should make a difrance in my opinion.
Do you have an other idee i can try?

Just as a side not. Seven segment displays can be common anode or common cathode. Make sure you have the correct display for your driver and code.

Ron

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.