Error Message

When I try to upload the following code an error message comes up. To test if its the arduino or the code, I tried uploading other code and it worked. I’m not sure why a modified version of the following code worked, but this one didn’t. Thank you for you help. :slight_smile:

#include <Servo.h>
Servo Motor;
Servo Motor2;
const byte greenLED = 12;
const byte redLED = 13;
const unsigned long greenLEDinterval = 250;
const unsigned long redLEDinterval = 450;
unsigned long greenLEDtimer;
unsigned long redLEDtimer;
int servoPosition = 90;// the current angle of the servo - starting at 90.
int servoSlowInterval = 80; // millisecs between servo moves
int servoFastInterval = 10;
int servoInterval = servoSlowInterval; // initial millisecs between servo moves
int servoDegrees = 1;       // amount servo moves at each step
const int servoPin = 9; // the pin number for the servo signal
const int servoPin2 = 10;
const int servoMinDegrees = 20; // the limits to servo movement
const int servoMaxDegrees = 130;//Increase to increase servo ON time
unsigned long previousServoMillis = 0; // the time when the servo was last moved
unsigned long currentMillis = 0;
void setup() {
 Serial.begin(9600);
 pinMode (greenLED, OUTPUT);
 pinMode (redLED, OUTPUT);
 greenLEDtimer = millis ();
 redLEDtimer = millis ();
 Serial.begin(9600);
 Serial.println("Starting SeveralThingsAtTheSameTimeRev1.ino");  // so we know what sketch is running
 Motor.write(servoPosition); // sets the initial position
 Motor.attach(servoPin);
 Motor2.write(servoPosition);
 Motor2.attach(servoPin2);
}

void loop () {
 currentMillis = millis();
 servoSweep();
 currentMillis = millis();
 servoSweep2();
 if ( (millis () - greenLEDtimer) >= greenLEDinterval)
   toggleGreenLED ();
 if ( (millis () - redLEDtimer) >= redLEDinterval)
   toggleRedLED ();

}

void servoSweep() {
 // this is similar to the servo sweep example except that it uses millis() rather than delay()
 // nothing happens unless the interval has expired
 // the value of currentMillis was set in loop()
 if (currentMillis - previousServoMillis >= servoInterval) {
   // its time for another move
   previousServoMillis += servoInterval;
   servoPosition = servoPosition + servoDegrees; // servoDegrees might be negative
   if (servoPosition <= servoMinDegrees) {
     // when the servo gets to its minimum position change the interval to change the speed
     if (servoInterval == servoSlowInterval) {
       servoInterval = servoFastInterval;
     }
     else {
       servoInterval = servoSlowInterval;
     }
   }
 }
 if ((servoPosition >= servoMaxDegrees) || (servoPosition <= servoMinDegrees))  {
   Motor.detach();
 }
 // make the servo move to the next position
 Motor.write(servoPosition);
 // and record the time when the move happened
}


void servoSweep2() {
 // this is similar to the servo sweep example except that it uses millis() rather than delay()
 // nothing happens unless the interval has expired
 // the value of currentMillis was set in loop()
 if (currentMillis - previousServoMillis >= servoInterval) {
   // its time for another move
   previousServoMillis += servoInterval;
   servoPosition = servoPosition + servoDegrees; // servoDegrees might be negative
   if (servoPosition <= servoMinDegrees) {
     // when the servo gets to its minimum position change the interval to change the speed
     if (servoInterval == servoSlowInterval) {
       servoInterval = servoFastInterval;
     }
     else {
       servoInterval = servoSlowInterval;
     }
   }
   if ((servoPosition >= servoMaxDegrees) || (servoPosition <= servoMinDegrees))  {
     Motor2.detach();
   }
   // make the servo move to the next position
   Motor2.write(servoPosition);
   // and record the time when the move happened
 }
}

void toggleGreenLED ()
{
 if (digitalRead (greenLED) == LOW)
   digitalWrite (greenLED, HIGH);
 else
   digitalWrite (greenLED, LOW);

 greenLEDtimer = millis ();

}

void toggleRedLED ()
{
 if (digitalRead (redLED) == LOW)
   digitalWrite (redLED, HIGH);
 else
   digitalWrite (redLED, LOW);

 redLEDtimer = millis ();
}

(deleted)

Here's the error message c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.9.2/../../../../avr/lib/avr5/crtatmega328p.o:(.init9+0x0): undefined reference to `main'

collect2.exe: error: ld returned 1 exit status

exit status 1 Error compiling for board Arduino/Genuino Uno.

Did you read this?

WHY NOT?

(deleted)

(deleted)

Compiled for me: Win10, Arduino 1.6.12

But then, for all I know when you edited the opening post you replaced bad code with good.