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!
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;
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.
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!
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:
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.
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?
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.
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.
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?
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.