Go Down

Topic: motor code error (Read 3 times) previous topic - next topic

arduinosoccer33k

I am very new to code and all that I'm trying to do is to get the thing to spin. It is hooked up to an ESC and to the Arduino. When I try to upload it, it gives me this error on the first line:

sketch_jan04f:1: error: expected constructor, destructor, or type conversion before '.' token

Here is the code:

motor.attach(9)
motor.write(0)
motor.write(10)
motor.write(20)
motor.write(30)
motor.write(35)
motor.write(40)
motor.write(45)
motor.write(50)
motor.write(60)
motor.write(70)

PaulS

Quote
Here is the code:

Every;
statement;
in;
C;
ends;
with;
a;
semicolon;.

arduinosoccer33k

It still gives me the same error even with the semicolons.
I am almost totally clueless about code
If you have any tips or improvements or suggestions on my code (above) please post a reply

PaulS

Quote
It still gives me the same error even with the semicolons.

Then we need to see all of your code, not just a snippet.

arduinosoccer33k

That is the whole thing.
I'm completely clueless

PaulS

Quote
That is the whole thing.
I'm completely clueless

I guess.

Every Arduino sketch has a setup() function and a loop() function, and all executable code goes in one of those functions, or some other function.

arduinosoccer33k

HOW AND WHEN DO I USE THESE FUNCTIONS?
I tried looking it up and I only got more confused. Could you also tell me where and how to use these functions in my code?

PaulS

Quote
HOW AND WHEN DO I USE THESE FUNCTIONS?

The Arduino executes main() when powered up. The main() function calls init(), setup(), and loop(), in an endless loop. You don't have to use these functions. You just have to supply them.

There are dozens of sample sketches provided with the IDE that show how setup() and loop() are structured. Running some of them would show how they are used.

arduinosoccer33k

Is adding slashes and stars necessary?

arduinosoccer33k

Along with descriptions of each code or function

PaulS

Quote
Is adding slashes and stars necessary?

No, but sometimes it can be useful. It's hard to multiply without stars and hard to divide with slashes.

Quote
Along with descriptions of each code or function

Not if you have a phenomenal memory. What were we talking about?  8)

arduinosoccer33k

I meant the little descriptions next to the code.

Also are you saying that the stars and slashes are for multiplying and dividing?

Grumpy_Mike

Quote
Also are you saying that the stars and slashes are for multiplying and dividing?

Yes.
Start looking at the example code found in the arduino IDE, that is the software you have running on your PC. Look in the File -> Examples menu to get started.
You are a way off being able to control motors yet until you learn the basics.

arduinosoccer33k

I created this code. Although it uploaded just fine without any problems, the motor would not spin. FYI It is hooked up to an ESC

#include <Servo.h>
Servo motor;  // create servo object to control a servo

void setup() {
  Serial.begin(9600);
  motor.attach(9);  //the pin for the servo control
}

void loop() {
motor.write(0);
motor.write(10);
motor.write(20);
motor.write(30);
motor.write(35);
motor.write(40);
motor.write(45);
motor.write(50);
motor.write(60);
motor.write(70);
motor.write(80);
motor.write(90);
}

wildbill


I meant the little descriptions next to the code.

Also are you saying that the stars and slashes are for multiplying and dividing?


I assume your original question refers to comments // or /*  */

If those are unfamiliar, you might consider looking at some C/C++ tutorials as well as the examples provided with the IDE.

Go Up