sleep in arduino

Thread Starter

filipmr

Joined Jan 2, 2021
52
I am building a digital clock with an arduino and a 4 digit 7 segment display, and I need to change the minutes every 60 seconds by +1. If i put delay it doesnt work with my display. What should I do?
 

djsfantasi

Joined Apr 11, 2010
7,229
I am building a digital clock with an arduino and a 4 digit 7 segment display, and I need to change the minutes every 60 seconds by +1. If i put delay it doesnt work with my display. What should I do?
First, explain to us what you mean by “it doesn’t work with my display”?

Second, attach your code. Click on the ellipsis (thread dots) icon above and paste or insert your code between the “][“ characters.

I am curious to see the statement where you use delay().

Have you tried to just display some four digit number? Are you sure the display works?
 

Thread Starter

filipmr

Joined Jan 2, 2021
52
C:
#include "SevSeg.h"

SevSeg sevseg;
int s=0000;
int mix;//all in minutes
int m=0;//minutes
int h=0;//hours

void setup() {
 
 
  m=0;
  h=0;
  Serial.begin(9600);
  // put your setup code here, to run once:
  byte numDigits=4;
  byte digitPins[]={10,11,12,13};
  byte segmentPins[] = {9,2,3,5,6,8,7,4};
  bool resistorsOnSegments = true;
  bool updateWithDelaysIn = true;
  byte hardwareConfig = COMMON_CATHODE;
  sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments);

}

void loop() {
  int x;
  mix=m+h*60;
  m=mix%60;
  h=(mix-m)/60;
  if(h<10){
    x=1;
  }
  if(h>=10){
    x=2;
  }
  s=m+h*100;
  sevseg.setNumber(s,x);
  sevseg.refreshDisplay();
  mix=mix+1;
  delay(60000);







   

}
The display doesnt show anything when I use the delay function
 

Thread Starter

filipmr

Joined Jan 2, 2021
52
Ok, so we know the display works. Now replace the delay command, but instead of a parameter of 60000, use 2000...
I didnt see that you typed while(-1) , i just saw what if u deleted delay() , when i put while(-1) it doesnt show anything, and when i delete delay and dont put anything it shows 0.0
 

djsfantasi

Joined Apr 11, 2010
7,229
I have been reviewing the library documentation for SevSeg, Your last mistake and what I’ve learned may explain your problem.

You need to call .refreshDisplay() repeatedly. Look at the comments in the documentation examples. By using delay(), you don’t refresh the display often enough.

You need to change your code to only increment your counter once every 60 seconds and still call .refreshDisplay() every time loop() is executed. To do this, you’ll need to use millis() and check to see if 60 seconds have elapsed. That way, the refresh function can be called during the 60 second period.
 

Thread Starter

filipmr

Joined Jan 2, 2021
52
I have been reviewing the library documentation for SevSeg, Your last mistake and what I’ve learned may explain your problem.

You need to call .refreshDisplay() repeatedly. Look at the comments in the documentation examples. By using delay(), you don’t refresh the display often enough.

You need to change your code to only increment your counter once every 60 seconds and still call .refreshDisplay() every time loop() is executed. To do this, you’ll need to use millis() and check to see if 60 seconds have elapsed. That way, the refresh function can be called during the 60 second period.
Thank you, I will look it up
 
Top