I am getting an error message "Clockwise was not declared in this scope"
The code is cut and pasted from code tried earlier which worked? I put the temporary break lines to break up my code thinking there was a curly bracket missing. Tilt gets called earlier Thanks
void Tilt()
{
if (turnDirection == turnClockwise) {
clockwise();
} else if ((turnDirection == turnAnticlockwise)) {
anticlockwise();
}
// ---------------------------------------------------
void clockwise()
{
for (int i = 0; i < 8; i++) // clockwise
{
setOutput(i);
delayMicroseconds(motorSpeed);
}
}
// ---------------------------------------------------
void anticlockwise()
{
for (int i = 7; i >= 0; i--) // anticlockwise
{
setOutput(i);
delayMicroseconds(motorSpeed);
}
}
Well, your error "Clockwise was not declared in this scope" shows a capital and the code is all lower case. So the code isn't quite matching your error message is it?
Thanks Pete, however I cannot understand why I would do that. The Tilt subroutine/function gets called first, and within that it decides if my stepper is to go clockwise or anticlockwise.
Putting the cart after the horse leaves this early part of code isolated?
if (turnDirection == turnClockwise) {
clockwise();
} else if ((turnDirection == turnAnticlockwise)) {
anticlockwise();
}
ZOR2:
The code shown are functions that are below Void Loop and Void Setup.
So, why not post that?
It's:
a) much quicker to copy past all (just hit Ctrl+A and Ctrl+V)
b) what you must do as you can read in How to use the forum
Why?
a) Now we can also compile it without having to add all sorts of crap
b) We know it matches what you have; and
c) if you also gave the whole error we can match the line number for example
Aka, posting the WHOLE code and the WHOLE error would have saved you all this and the answer would have been given already
The code shown are functions that are below Void Loop and Void Setup.
You are doing it again. Using capitals where they should not be. As it happens most of us would just read what you wrote and understand what you meant, but that will not always be the case, so being precise is very important.
Thanks oqibididipo, I will put it together bit by bit and solve it, thanks for your help.
It's basically a control structure that with the information I have shown should have been recognised by those that know, and not picky like V or v. C or c.
I am not putting up the code as I would get inandated by why do you do this and that, all non relevant to my problem.
It was clear what I was trying to do, call a function from void loop, go to that function and with whatever values were given then call functions within the Tilt function, and turn a stepper in the direction I wanted.
I could not have simply cut and pasted all code as there are various hooks for later completion.
Won't say anymore as don't want to say what I really want to say.
Such errors are even more obvious if you put each brace on its own line then Auto Format the code (or do both at once by altering the Auto Format parameters). The code blocks stand out better with the code formatted like this.
If you look in File/Preferences in the IDE you will see the location of the preferences.txt file. Open that location and put the following in a file named formatter.conf
# This configuration file contains a selection of the available options provided by the formatting tool "Artistic Style"
# http://astyle.sourceforge.net/astyle.html
#
# If you wish to change them, don't edit this file.
# Instead, copy it in the same folder of file "preferences.txt" and modify the copy. This way, you won't lose your custom formatter settings when upgrading the IDE
# If you don't know where file preferences.txt is stored, open the IDE, File -> Preferences and you'll find a link
# 2 spaces indentation
indent=spaces=2
# also indent macros
indent-preprocessor
# indent classes, switches (and cases), comments starting at column 1
indent-classes
indent-switches
indent-cases
indent-col1-comments
# put a space around operators
pad-oper
# put a space after if/for/while
pad-header
# if you like one-liners, keep them
# keep-one-line-statements
#Move opening brackets onto new line
--style=allman --style=bsd --style=break -A1
I found the details of this somewhere in this forum