Function error

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?

-jim lee

Sorry Jim, did in hurry

"clockwise was not declared in this scope"

Thanks

Why not simply click the "copy error message" then? A hell lot quicker and it gives us a hell lot more info :slight_smile:

Oww, and did I mention copying all the code is also quicker then copying stupid snippets? Where is loop()? Where is setup()?

The code shown are functions that are below Void Loop and Void Setup.

The Tilt function is called within the Void Loop. It just goes there to turn a motor. (stepper)

Move the Tilt function after the anticlockwise function.

Pete

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();
  }

Too much trouble to post ALL the code?

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 :wink:

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 :wink:

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.

Your { { } { } don't match.

Tools > Auto Format will help you catch this kind of errors.

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.

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.

How do you know what is relevant or not ? For instance, you could have a global and local variable with the same name. How would we know ?

If you don't want to post your full program then why not write a small one that exhibits the problem ?

and not picky like V or v. C or c.

If you think that I am picky then the compiler is a 100 times worse. When programming, details matter.

UKHeliBob:
If you think that I am picky then the compiler is a 100 times worse. When programming, details matter.

Amen :slight_smile:

Thanks oqibidipo, you were right, { wrong.

ZOR2:
Thanks oqibidipo, you were right, { wrong.

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.

Thanks, however I still have format problems.

I have tried reducing the indentation and then using auto format, but formatting is sometimes still all over the place.

Maybe it's because I don't always type in code correctly?

eg:

if (turnDirection == turnClockwise) {

or

if (turnDirection == turnClockwise)
{

The curly bracket never seems to put itself where it is supposed to go. Which position should it be in?

Thanks

Which position should it be in?

Either will work. What is important is that there is a corresponding closing curly bracket at the end of the code block

if (turnDirection == turnClockwise) {
    //do something
    //do this as well
  }  //end of code block

is OK but I prefer

if (turnDirection == turnClockwise) 
  {
    //do something
    //do this as well
  }  //end of code block

either will work. It is a matter of personal preference. I modified the parameters for Auto Format to put the curly brackets on their own line.

Thanks.

Yes your second line of code looks much cleaner to read/view brackets. Is there a setting hidden somewhere on the auto format setting to do this.

Regards

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