Function error

Hi all,
I am trying to rotate a servo motor based on an excel file's data. When I run the code, it gives me the error "exit status 1, a function-definition is not allowed here before '{' token" on the Void loop line which is bolded and underlined in the code. This is the code:

#include <SPI.h>
#include <SD.h>
#include <Servo.h>

Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0; // variable to store the servo position
const int chipSelect = 4;
int i = 0; //Index of SunAzimuth angle
float Main_Array[91]; //List of Azimuth angles
int len = sizeof(Main_Array) / sizeof(Main_Array[0]);
File myFile;

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}

Serial.print("Initializing SD card...");

// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
while (1);
}
Serial.println("card initialized.");

// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.

myFile = SD.open("14.csv");
//while (myFile.available()){
for (int i = 0; i <= 90; i++) {
Main_Array = myFile.parseFloat();
//Serial.println(Main_Array*);}
_
//}_
_
myFile.close();_
_
myservo.attach(9); // attaches the servo on pin 9 to the servo object*_
* }*
** void loop() {**
* for (pos = 0; pos <= len; pos += 1) { // goes from 0 degrees to 180 degrees*
* // in steps of 1 degree*
* float x = Main_Array[pos];
_
Serial.println(x);_
_
myservo.write(x); // tell servo to go to position in variable 'pos'_
_
delay(2000); // waits 150 s for the servo to reach the position*_
* }*
* exit(0);*
* }*
The thing is that when I wanted to do it through a list of data, it works well without any error. The code is:
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
int i=0;
*int a[]={60, 80, 120, 160}; *
int len = sizeof(a) / sizeof(a[0]);
void setup() {
* myservo.attach(9); // attaches the servo on pin 9 to the servo object*
* Serial.begin(9600); // Other baud rates can be used...*
Serial.println( len);
}
void loop() {
* for (pos = 0; pos <= len; pos += 1) { // goes from 0 degrees to 180 degrees*
* // in steps of 1 degree*
* int x = a[pos];*
* Serial.println(x);*
* myservo.write(x); // tell servo to go to position in variable 'pos'*
* delay(2000); // waits 150 s for the servo to reach the position*
* }*
* exit(0);*
}
Would be great to help me if I am wrong somewhere.
Thanks

What is

Main_Array = myFile.parseFloat();

supposed to do?

Do an auto format (in the IDE use ctrl-t or Tools, Auto Format) your code. You may see where you are missing a bracket.

Post code in code tags. See the forum guidelines.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.