compile error / servo. learning the hard way

Hi people!

First of all, I am very very new to this world. I never wrote a piece of code, I am still trying to understand the code that is already written.

I found a servo (http://www.carson-modelsport.com/de/produkte/fernsteueranlagen/servos/produktdetails.htm?sArtNr=500502024) and I want to try to control it with my arduino mega. For this, I found (Arduino Playground - SingleServoExample)

I installed Software Servo Library and Servo Library, made the connections, and pasted the code in my IDE.

#include <Servo.h>

Servo servo1; Servo servo2; 


void setup() {

  pinMode(1,OUTPUT);
  servo1.attach(14); //analog pin 0
  //servo1.setMaximumPulse(2000);
  //servo1.setMinimumPulse(700);

  servo2.attach(15); //analog pin 1
  Serial.begin(19200);
  Serial.println("Ready");

}

void loop() {

  static int v = 0;

  if ( Serial.available()) {
    char ch = Serial.read();

    switch(ch) {
      case '0'...'9':
        v = v * 10 + ch - '0';
        break;
      case 's':
        servo1.write(v);
        v = 0;
        break;
      case 'w':
        servo2.write(v);
        v = 0;
        break;
      case 'd':
        servo2.detach();
        break;
      case 'a':
        servo2.attach(15);
        break;
    }
  }

  Servo::refresh();

}

When I compile it, the following errors appear:

D:\temp\Arduino\libraries\Servo\Servo.cpp: In member function 'uint8_t Servo::attach(int)':
D:\temp\Arduino\libraries\Servo\Servo.cpp:28: error: 'digitalWrite' was not declared in this scope
D:\temp\Arduino\libraries\Servo\Servo.cpp:29: error: 'OUTPUT' was not declared in this scope
D:\temp\Arduino\libraries\Servo\Servo.cpp:29: error: 'pinMode' was not declared in this scope
D:\temp\Arduino\libraries\Servo\Servo.cpp: In member function 'void Servo::write(int)':
D:\temp\Arduino\libraries\Servo\Servo.cpp:52: error: 'clockCyclesPerMicrosecond' was not declared in this scope
D:\temp\Arduino\libraries\Servo\Servo.cpp: In static member function 'static void Servo::refresh()':
D:\temp\Arduino\libraries\Servo\Servo.cpp:74: error: 'millis' was not declared in this scope
D:\temp\Arduino\libraries\Servo\Servo.cpp:107: error: 'digitalWrite' was not declared in this scope
D:\temp\Arduino\libraries\Servo\Servo.cpp:109: error: 'TCNT0' was not declared in this scope
D:\temp\Arduino\libraries\Servo\Servo.cpp:124: error: 'digitalWrite' was not declared in this scope

Suggestions?

thanks for sharing!

and I want to try to control it with my arduino mega.

servo1.attach(14); //analog pin 0

Is analog 0 really pin 14 on a Mega?
A0 is a better choice than 14.
What sort of PC are you using, with what operating system, and what version of the IDE?

there is a difference in versions 1 and 2 check for correct libray.
first error is because uint and int are not same
analog is not needed.but it uses a timedsignal, some ask for pwm output.
this depends on type of board, so you will need to do a setup.

I compiled the code above and got the following error message:

sketch_nov09a.ino: In function 'void loop()':
sketch_nov09a:47: error: 'refresh' is not a member of 'Servo'

I removed the "refresh" and got the following error message

Binary sketch size: 4,026 bytes (of a 32,256 byte maximum)

Windows 7, IDE 1.0.5

WIN XP
IDE 1.0.5

I installed Software Servo Library and Servo Library, made the connections, and pasted the code in my IDE.

The Servo library is a core library. Whatever it was you installed was unnecessary, for that example. I'd suggest that you uninstall it.