Pages: [1] 2 3 4   Go Down
Author Topic: motor code error  (Read 2893 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 38
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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)
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 48993
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Here is the code:
Every;
statement;
in;
C;
ends;
with;
a;
semicolon;.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 38
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 48993
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 38
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 48993
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 38
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 48993
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 38
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is adding slashes and stars necessary?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 38
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Along with descriptions of each code or function
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 48993
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?  smiley-cool
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 38
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I meant the little descriptions next to the code.

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

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 618
Posts: 33938
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 38
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

New Jersey
Offline Offline
Faraday Member
**
Karma: 66
Posts: 3670
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1] 2 3 4   Go Up
Jump to: