Timer with Seven Segment Display

I’m currently using the “SevSeg” Arduino Library to control a 4 digit 7 Segment Display and
have been attempting to create a simple timer.
My Code is as Follows:

#include "SevSeg.h"
SevSeg sevseg;
int number = 0;
void setup() {
** // put your setup code here, to run once:**
** byte numDigits = 4;**

** byte digitPins = {2, 3, 4, A5};**
** byte segmentPins = {5, 7, A3, A2, A1, 6, A4, A0};**
** sevseg.begin(COMMON_ANODE, numDigits, digitPins, segmentPins);**
** sevseg.setBrightness(100);**

void loop() {
** // put your main code here, to run repeatedly:**
** sevseg.setNumber(number);**
** sevseg.refreshDisplay();**
** number += 1;**
** delay(1000);**

I have since realised that the delay function doesn’t work with this library, but couldn’t find any
Does anyone know a good solution or resource to use?

OK, first things first.

You need to go and read the forum instructions so that you can go back and modify your original post (not re-post it) - using the “More → Modify” option below the right hand corner of your post - to mark up your code as such using the “</>” icon in the posting window. Just highlight each section of code (or output if you need to post that) from the IDE and click the icon.

In fact, the IDE has a “copy for forum” link to put these markings on a highlighted block for you so you then just paste it here in a posting window. But even before doing that, don’t forget to use the “Auto-Format” (Ctrl-T) option first to make it easy to read. If you do not post it as “code” it can as you now see, be quite garbled and is always more difficult to read.

It is inappropriate to attach it as a “.ino” file unless it is clearly too long to include in the post proper. People can usually see the mistakes directly and do not want to have to actually load it in their own IDE. And that would also assume they are using a PC and have the IDE running on that PC.

Also tidy up your blank space. Do use blank lines, but only between complete functional blocks.

No, you are right. The delay function doesn’t work with this library.

Actually, the delay() function is generally useless for most things.

You need to understand how to use “loop()”. The loop must be continuously running, it must not stop, which means - it must not contain any form of delay.

So what you need to do is to check millis() each time in the loop, and determine whether it has advanced by 1000 - that is, one second - since you last checked it, and if it has, then increment “number”. Can you figure out the code to do that?

OK, I will tell you since someone else undoubtedly will since they do not expect you to do it yourself - check out this explanatory thread. :roll_eyes: