Loop not repeating

Hello everyone. I am trying to make a loop with a delay using the milli() function. The purpose of the project will eventually be a servomotor repeatedly moving until an LDR senses darkness for longer than the normal pattern. The problem I am experiencing is the loop I made never repeats. I have tried reworking the code multiple times in different ways but I am inexperienced and do not fully understand the language yet. I would very much appreciate some feedback and I hope someone could help me with my problem. The code is below, thank you for reading!

(2 tabs)

Tab #1

#include <Servo.h>

Servo servo1; //Start//
Servo servo2; //A button/

void setup()
{
servo1.attach(9);
servo2.attach(11);
}

void loop() {
servoLoopA;
}
//2.5 sec; then A button//
//5 sec; then A button//
//4 sec; then A button//
//1.5 sec; then A button * 3//
//7 sec; then start IF not shiny//

Tab#2

#include <Servo.h>

const unsigned long eventInterval = 1000;
unsigned long previousTime = 0;

void servoLoopA (void) {

unsigned long currentTime = millis();

if (currentTime - previousTime >= eventInterval) {
servo2.writeMicroseconds(500);
servo2.writeMicroseconds(800);
previousTime = currentTime;
}
}

Seems like you miss () behind the call to servoLoopA:

void loop() {
 servoLoopA();
}

Of course you need the '()'. You can not isolate some aspect of a syntax and not maybe say that it could be improved, such as by allowing identifiers to call a function. The problem is the way some interpretation of such an aspect could conflict with the rest of the rules. Making a language involves trade offs between different aspects. In the C (dunno sort of) viewpoint, the brackets make perfect sense, since the name of a function already has a different interpretation, which is as a function pointer. I believe there must be some language, perhaps many, in which you can call a function solely by its name. Forth is one. But in Forth it is perfectly and easily supported by the syntax.

I should also point out it’s considered very bad practice to put c code (i.e. functions and global variable initialisers) in h files.

pcbbc:
I should also point out it’s considered very bad practice to put c code (i.e. functions and global variable initialisers) in h files.

Ignoring for the moment whether or not it is bad practice, I can see no evidence that is what the OP has done. There is no indication of the name and extension of the file in tab 2 and it could well be a .ino file for all we know

The file itself is a .ino file. At the moment, I am very ignorant in the usage of c++ and find it difficult to understand some of the quirks of the language. I cannot find any problems with the code and I do not really understand what your thoughtful comments have to say, and I am apologetic about that. If possible, could you use layman's terms for me? I am the epitome of "self-taught" and only really researched the specific things i need to use for this project.
Thank you all so much!

You should take a look at the Arduino functions tutorial. The last line of the tutorial says:

As you can see, even if a function does not have parameters and no returns is expected "(" and ")" brackets plus ";" must be given.

Read the tutorial then read reply #1 again then look at the contents of your loop().

BTW, you don't need separate tabs, I recommend you put everything in one tab. It might be less confusing.

Surprisingly, it compiles.
In my experience, when you define globals in a tab (other than the first one), strange things happen. What you have done is, in one sketch:

#include <Servo.h>

Servo servo1; //Start//
Servo servo2; //A button/
         
void setup()
{
  servo1.attach(9);
  servo2.attach(11);
}

void loop() {
 servoLoopA;
}

#include <Servo.h>

const unsigned long eventInterval = 1000;
unsigned long previousTime = 0;

void servoLoopA (void) {

unsigned long currentTime = millis();
 
  if (currentTime - previousTime >= eventInterval) {
    servo2.writeMicroseconds(500);
    servo2.writeMicroseconds(800);
    previousTime = currentTime;
  }
}

I am pretty sure that eventInterval and previousTime aren't being initialized.

Tabs are very handy for organizing large programs. I use them to put one function in each tab. But all of the globals, defines, and includes have to be at the top of the first tab. The compiler simply reads the tabs in sequence.

SteveMann:
I am pretty sure that eventInterval and previousTime aren't being initialized.

I don't know why you think that, but I am certain that servoLoopA is not being called

aarg:
[...] In the C (dunno sort of) viewpoint, the brackets make perfect sense, since the name of a function already has a different interpretation, which is as a function pointer. [...].

These : [ ], { }, ( ) are all brackets. In C/C++ Programming language context, they have (probably) different names. Should we use those names during writing and speaking?

GolamMostafa:
These : [ ], { }, ( ) are all brackets. In C/C++ Programming language context, they have (probably) different names. Should we use those names during writing and speaking?

[ ] brackets
{ } braces
( ) parentheses

(deleted)

Hi Sam,

fi you want to code it yourself there is a learning-curve to walk up. There is no way around it.
As long as you show that you do at least a small laerning by yourself you will allways get answers here in the forum.
But it is important to do some learning on your own.

From your code

if (currentTime - previousTime >= eventInterval) {[color=#222222][/color]
    servo2.writeMicroseconds(500);[color=#222222][/color]
    servo2.writeMicroseconds(800);[color=#222222][/color]
    previousTime = currentTime;[color=#222222][/color]
  }

I estimate that your understanding how the code works is very improvable.
the two commands

servo2.writeMicroseconds(500);[color=#222222][/color]
    servo2.writeMicroseconds(800);

set the servo-signal to 500 microseconds and only 0,000001 seconds later to 800 microseconds
This means the servo has no time to turn. I guess it is jiggering without really moving.
I guess it was your try to make the servo to turn left/right/left/right.....
the servo needs some time to do the turning.
So this means there has to be a pause between the two commands
please describe in normal words what should the servo do
what shalll the speed of the turning be maximum what the servo can do or slower?
shall there be a pause before turning in the opposite direction?
The Arduino-website has a lot of tutorials not all of them are best.
I recomend this tutorial

It is easy to understand and a good mixture between writing about important concepts
and get you going.

best regards Stefan

if (currentTime - previousTime >= eventInterval) {[color=#222222][/color]
    servo2.writeMicroseconds(500);[color=#222222][/color]
    servo2.writeMicroseconds(800);[color=#222222][/color]
    previousTime = currentTime;[color=#222222][/color]
  }

Did you by any chance do something wrong when copying the code ?

TheMemberFormerlyKnownAsAWOL:
[ ] brackets
{ } braces
( ) parentheses

1. In our native language (Bangla), these are called: third brackets, second brackets, and first brackets respectively. Are there any similar native names for the English speaking people?

2. In C language context, which one of the following two writing styles is appropriate?
(1) A function is followed by a pair of parentheses.
(2) A function is followed by brackets. (is seen to have been written in Post#2)

GolamMostafa:
1. In our native language (Bangla), these are called: third brackets, second brackets, and first brackets respectively. Are there any similar native names for the English speaking people?

See reply #10

2. In C language context, which one of the following two writing styles is appropriate?
(1) A function is followed by a pair of parentheses.
(2) A function is followed by brackets. (is seen to have been written in Post#2)

(3) a function is followed by braces.
Depends on what you call "a function".
A definition?
A declaration?
A function call?
An indexed function table?

So the answer is "all of the above"

Thank you all so much! You totally fixed my problem. I will work hard to learn more about this amazing and useful skill.

TheMemberFormerlyKnownAsAWOL:
See reply #10
(3) a function is followed by braces.
Depends on what you call "a function".
A definition?
A declaration?
A function call?
An indexed function table?

So the answer is "all of the above"

1. I have seen like this:

timeDelay();     //this is function call

2. I have seen like this:

int valueCalculate(arg);    //this is function declaration

3. I have seen like this:

void loop()    //this is function definition
{

}

4. I have not seen like this:

void setup    //function name followed by a pair of braces
{

}

5. I have no idea what is "An indexed function table"! Would appreciate an example.

(void)fnTable [index] (); is a call to a function in a table of function pointers.
I have chosen to ignore the return value.

The example ((void)fnTable [index] ();) has well clarified the meaning of the sentence -- An indexed function table.

Cool!