Error with Serial does not name a type

What did you have to change in order for it to c0mpile without errors?

What fixed the "Serial does not name a type" error?
I'm having the same problem with my code:

#include <Brain.h>
#include <Servo.h>

///////////////////////////////////////////////////////
// mindflexservo
///////////////////////////////////////////////////////

Serial.begin(9600);

myservo.attach(9); // attaches the servo on pin 9 to the servo object
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);

void loop() { // Expect packets about once per second.
// The .readCSV() function returns a string (well, char*) listing
//the most recent brain data, in the following format:
// "signal strength, attention, meditation, delta, theta, low // alpha, high alpha, low beta, high beta, low gamma, // high gamma"

if (brain.update()) {

 // Serial.println(brain.readErrors()); 
 // Serial.println(brain.readCSV()); 		
 //sprintf(a, "%c",brain.readCSV()); 

a = brain.readCSV(); 

v = a.indexOf(','); 
v = a.indexOf(',',v+1); 
v = a.indexOf(',',v+1); 
v = a.indexOf(',',v+1); 
z = a.indexOf(',',v+1); 

a1 = a.substring(v+1,z); 
num = a1.toInt(); 			 
v=a.indexOf(',',z+1); 

a = a.substring(z+1,v); 

num1 = a.toInt();
Serial.print("alpha =  "); 
Serial.println(num1); 		

output = map(num,0,999999,0,180); 

myservo.write(output); 	// tell servo to go to position in variable 'pos' 

delay(15); 

 // analogWrite(12,output); 

//brain.readCS).toCharArray(a,200); 

}
And I m receiving the following compile errors

C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino:8:1: error: 'Serial' does not name a type
Serial.begin(9600);
^~~~~~
C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino:11:1: error: 'myservo' does not name a type; did you mean 'Servo'?
myservo.attach(9); // attaches the servo on pin 9 to the servo object
^~~~~~~
Servo
C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino:12:8: error: expected constructor, destructor, or type conversion before '(' token
pinMode(12, OUTPUT);
^
C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino:13:8: error: expected constructor, destructor, or type conversion before '(' token
pinMode(11, OUTPUT);
^
C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino: In function 'void loop()':
C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino:22:7: error: 'brain' was not declared in this scope
if (brain.update()) {
^~~~~
C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino:22:7: note: suggested alternative: 'Brain'
if (brain.update()) {
^~~~~
Brain
C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino:28:5: error: 'a' was not declared in this scope
a = brain.readCSV();
^
C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino:30:5: error: 'v' was not declared in this scope
v = a.indexOf(',');
^
C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino:34:5: error: 'z' was not declared in this scope
z = a.indexOf(',',v+1);
^
C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino:36:5: error: 'a1' was not declared in this scope
a1 = a.substring(v+1,z);
^~
C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino:36:5: note: suggested alternative: 'A1'
a1 = a.substring(v+1,z);
^~
A1
C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino:37:5: error: 'num' was not declared in this scope
num = a1.toInt();
^~~
C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino:37:5: note: suggested alternative: 'enum'
num = a1.toInt();
^~~
enum
C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino:42:5: error: 'num1' was not declared in this scope
num1 = a.toInt();
^~~~
C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino:42:5: note: suggested alternative: 'enum'
num1 = a.toInt();
^~~~
enum
C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino:46:5: error: 'output' was not declared in this scope
output = map(num,0,999999,0,180);
^~~~~~
C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino:48:5: error: 'myservo' was not declared in this scope
myservo.write(output); // tell servo to go to position in variable 'pos'
^~~~~~~
C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino:48:5: note: suggested alternative: 'Servo'
myservo.write(output); // tell servo to go to position in variable 'pos'
^~~~~~~
Servo
C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino:56:3: error: expected '}' at end of input

  • }*
  • ^*

exit status 1

Compilation error: 'Serial' does not name a type

Thanks!

What fixed the Serial does not name a type error?
Iam having the same problem with my code

#include <Brain.h>
#include <Servo.h>

///////////////////////////////////////////////////////
// mindflexservo
///////////////////////////////////////////////////////

Serial.begin(9600);

myservo.attach(9); // attaches the servo on pin 9 to the servo object
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);

void loop() { // Expect packets about once per second.
// The .readCSV() function returns a string (well, char*) listing
//the most recent brain data, in the following format:
// "signal strength, attention, meditation, delta, theta, low // alpha, high alpha, low beta, high beta, low gamma, // high gamma"

if (brain.update()) {

 // Serial.println(brain.readErrors()); 
 // Serial.println(brain.readCSV()); 		
 //sprintf(a, "%c",brain.readCSV()); 

a = brain.readCSV(); 

v = a.indexOf(','); 
v = a.indexOf(',',v+1); 
v = a.indexOf(',',v+1); 
v = a.indexOf(',',v+1); 
z = a.indexOf(',',v+1); 

a1 = a.substring(v+1,z); 
num = a1.toInt(); 			 
v=a.indexOf(',',z+1); 

a = a.substring(z+1,v); 

num1 = a.toInt();
Serial.print("alpha =  "); 
Serial.println(num1); 		

output = map(num,0,999999,0,180); 

myservo.write(output); 	// tell servo to go to position in variable 'pos' 

delay(15); 

 // analogWrite(12,output); 

//brain.readCS).toCharArray(a,200); 

}
Iam receiving the following compile errors:

C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino:8:1: error: 'Serial' does not name a type
Serial.begin(9600);
^~~~~~
C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino:11:1: error: 'myservo' does not name a type; did you mean 'Servo'?
myservo.attach(9); // attaches the servo on pin 9 to the servo object
^~~~~~~
Servo
C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino:12:8: error: expected constructor, destructor, or type conversion before '(' token
pinMode(12, OUTPUT);
^
C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino:13:8: error: expected constructor, destructor, or type conversion before '(' token
pinMode(11, OUTPUT);
^
C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino: In function 'void loop()':
C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino:22:7: error: 'brain' was not declared in this scope
if (brain.update()) {
^~~~~
C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino:22:7: note: suggested alternative: 'Brain'
if (brain.update()) {
^~~~~
Brain
C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino:28:5: error: 'a' was not declared in this scope
a = brain.readCSV();
^
C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino:30:5: error: 'v' was not declared in this scope
v = a.indexOf(',');
^
C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino:34:5: error: 'z' was not declared in this scope
z = a.indexOf(',',v+1);
^
C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino:36:5: error: 'a1' was not declared in this scope
a1 = a.substring(v+1,z);
^~
C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino:36:5: note: suggested alternative: 'A1'
a1 = a.substring(v+1,z);
^~
A1
C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino:37:5: error: 'num' was not declared in this scope
num = a1.toInt();
^~~
C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino:37:5: note: suggested alternative: 'enum'
num = a1.toInt();
^~~
enum
C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino:42:5: error: 'num1' was not declared in this scope
num1 = a.toInt();
^~~~
C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino:42:5: note: suggested alternative: 'enum'
num1 = a.toInt();
^~~~
enum
C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino:46:5: error: 'output' was not declared in this scope
output = map(num,0,999999,0,180);
^~~~~~
C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino:48:5: error: 'myservo' was not declared in this scope
myservo.write(output); // tell servo to go to position in variable 'pos'
^~~~~~~
C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino:48:5: note: suggested alternative: 'Servo'
myservo.write(output); // tell servo to go to position in variable 'pos'
^~~~~~~
Servo
C:\Users\Japper\Documents\Arduino\mindflexservo\mindflexservo.ino:56:3: error: expected '}' at end of input
** }**
** ^**

exit status 1

Compilation error: 'Serial' does not name a type

:

;
#include <Brain.h>
#include <Servo.h>

///////////////////////////////////////////////////////
// mindflexservo
///////////////////////////////////////////////////////

Serial.begin(9600);

myservo.attach(9); // attaches the servo on pin 9 to the servo object
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);

void loop() { // Expect packets about once per second.
// The .readCSV() function returns a string (well, char*) listing
//the most recent brain data, in the following format:
// "signal strength, attention, meditation, delta, theta, low // alpha, high alpha, low beta, high beta, low gamma, // high gamma"

if (brain.update()) {

 // Serial.println(brain.readErrors()); 
 // Serial.println(brain.readCSV()); 		
 //sprintf(a, "%c",brain.readCSV()); 

a = brain.readCSV(); 

v = a.indexOf(','); 
v = a.indexOf(',',v+1); 
v = a.indexOf(',',v+1); 
v = a.indexOf(',',v+1); 
z = a.indexOf(',',v+1); 

a1 = a.substring(v+1,z); 
num = a1.toInt(); 			 
v=a.indexOf(',',z+1); 

a = a.substring(z+1,v); 

num1 = a.toInt();
Serial.print("alpha =  "); 
Serial.println(num1); 		

output = map(num,0,999999,0,180); 

myservo.write(output); 	// tell servo to go to position in variable 'pos' 

delay(15); 

 // analogWrite(12,output); 

//brain.readCS).toCharArray(a,200); 

}

You forgot to put your code inside setup().

Outside function declarations you can only have variable declarations.

@iamiretheo
Hijacking the others thread is violation of the forum rules. Please create the new topic and put your question to it.

@

Topic split from another topic. Please do not add your own questions to the end of other people's topics.

Could you take a few moments to Learn How To Use The Forum

It will help you get the best out of the forum in the future.

Thank you.