I keep getting the error " undifined reference to 'setup'/ loop' "

i am using arduino droid to do this. after i fixed the other error i got this one " undifined reference to 'setup'/ loop' ". if you find the problem please tell me. or if i should use something different.

void setup() {
  // put your setup code here, to run once:

}

void loop() {
   
// code to control continuous rotation servo with potentiometer

#include <Servo.h>

Servo myservo; // create servo object to control a servo

int pot;    // variable for potentiometer analog reading, 0-123
int speed;  // variable for servo speed, 0-180.
            // servo is STOPPED at speed = 90
            // full speed in either direction at 0 or 180. 
            // this is NOT the servo's angular position

void setup() {
  // setup code that only runs once
  myservo.attach(8); // use pin 8 to control the servo
}

void loop() {
  // code that loops repeatedly
  pot = analogRead(A0);                // read analog voltage from potentiometer
  speed = map(pot, 0, 1023, 0, 180);   // convert analog reading 0-1023 to speed 0-180
  myservo.write(speed);                // send control signal to servo
}
put your main code here, to run repeatedly:
}


Your code contains two setup() and two loop() functions.
Please open blink example and see how to compose a sketch properly.

1 Like

It appears you embedded your sketch inside the first loop() function.

Try the following:

// code to control continuous rotation servo with potentiometer

#include <Servo.h>

Servo myservo; // create servo object to control a servo

int pot;    // variable for potentiometer analog reading, 0-123
int speed;  // variable for servo speed, 0-180.
            // servo is STOPPED at speed = 90
            // full speed in either direction at 0 or 180. 
            // this is NOT the servo's angular position

void setup() {
  // setup code that only runs once
  myservo.attach(8); // use pin 8 to control the servo
}

void loop() {
  // code that loops repeatedly
  pot = analogRead(A0);                // read analog voltage from potentiometer
  speed = map(pot, 0, 1023, 0, 180);   // convert analog reading 0-1023 to speed 0-180
  myservo.write(speed);                // send control signal to servo
}

thanks both of you it turns out i just had to take away the first viod loop/setup

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