1

i just set up 2 displays ( 3 digit 7 segments ), and the displays seems to be blinkin ( i know they are suppose to blink but so fast that the human eye cannot detect it ).

I'm using the SevSeg Library and this is how my code looks:

void setup() {

   byte numDigits = 3;
   byte digitPins[] = {2, 3, 4};
   byte segmentPins[] = {5, 6, 7, 8, 9, 10, 11, 12};
   sevseg1.begin(COMMON_ANODE, numDigits, digitPins, segmentPins);

   byte digitPins2[] = {14, 15, 16};
   byte segmentPins2[] = {17, 18, 19, 20, 21, 22, 23, 24};
   sevseg2.begin(COMMON_ANODE, numDigits, digitPins2, segmentPins2);

}

void loop() {

  while(true){
     sevseg1.setNumber(number,0);
     sevseg2.setNumber(number,1);
     sevseg1.refreshDisplay();  
     sevseg2.refreshDisplay();  
  }
}

I need to add 2 more 3 digits 7 segment displays so i was wondering what is it that is causing the blinking.

Im using Arduino Mega.

  • Could you give the link to SevSeg library? There several different libs with that name, I have checked 2 and none had the methods you use. – jfpoilpret Jan 16 '15 at 17:58
1

First of all, you have a while(true) in your loop, that makes no sense. The loop already loops for ever.

You are also changing the number every time the loop() is run, making it flicker. If you follow the Arduino library example, you can see they only use setNumber every so often and use refreshDisplay every time the code runs through the loop().

Also, you didn't setBrightness, which shouldn't be a problem since the library probably sets a default value, but I'd advise on including it in your code to eliminate unforeseen problems.

Try this code and let me know if it works:

#include "SevSeg.h"

SevSeg sevseg1; //Instantiate a seven segment controller object
SevSeg sevseg2;

void setup() {
  byte numDigits = 4;
  byte digitPins1[] = {2, 3, 4, 5};
  byte segmentPins1[] = {6, 7, 8, 9, 10, 11, 12, 13};
  byte digitPins2[] = {14, 15, 16};
  byte segmentPins2[] = {17, 18, 19, 20, 21, 22, 23, 24};

  sevseg1.begin(COMMON_ANODE, numDigits, digitPins1, segmentPins1);
  sevseg1.setBrightness(90);

  sevseg2.begin(COMMON_ANODE, numDigits, digitPins2, segmentPins2);
  sevseg2.setBrightness(90);
}

void loop() {
  static unsigned long timer = millis();
  static int deciSeconds = 0;

  if (millis() >= timer) {
    deciSeconds++; // 100 milliSeconds is equal to 1 deciSecond
    timer += 100; 
    if (deciSeconds == 10000) { // Reset to 0 after counting for 1000 seconds.
      deciSeconds=0;
    }
    sevseg1.setNumber(deciSeconds, 1);
    sevseg2.setNumber(deciSeconds, 1);
  }

  sevseg1.refreshDisplay(); // Must run repeatedly
  sevseg2.refreshDisplay(); // Must run repeatedly
}
  • Thanks for your response, i removed the while true, the thing that if i remove one 7 segment displays it doesn't blink. – Luis Javier Peña Ureña Jan 15 '15 at 13:49
  • Yes i did, but it is like if every time i do the .refreshDisplay(); it takes its time and shuts down the other display – Luis Javier Peña Ureña Jan 21 '15 at 0:55
  • I have completely revised my answer. Please do try ;) – Mr Jones Jan 21 '15 at 9:32
  • Actually, the while() does make a little sense; looping your code that way is a lot faster. – Tom Feb 20 '15 at 11:36
  • @Tom, actually this is Arduino's demo code, not mine. Using the while also makes it loop extremely fast. As you can see from this demo code, they only refresh the display ever 100ms, preventing it from continuously refreshing. – Mr Jones Feb 21 '15 at 11:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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