Servo2 - Library Files and Example

Does anybody have working library files for Servo2 and code which works with it.

MY library states I have contributed “ServoTimer2” and not “Servo2”… are they the same ???

I am getting very confused trying to get the simple Servo Knob code to work, using Servo2 library…

 Controlling a servo position using Timer 2 and a potentiometer (variable resistor) 
 by Michal Rinott <> 


//#include <Servo.h>                      //  imports servo library
//#include <Servo2.h>                    // ???? doesnt work - maybe one below - imports servo library
#include <ServoTimer2.h>              // ???? doesnt work - imports servo library

ServoTimer2 myServo;                         // associated myservo object will all resources in servo library

int const potpin = A0;                 // analog pin used to connect the potentiometer
int val;                               // variable to read the value from the analog pin measured at A0
int angle;                             // variable to read the servo angle value

void setup()
  myServo.attach(6);                   // attaches the servo on pin 6 (was 9) to the servo object
  Serial.begin(9600);                  // setup serial comms to read angle and volts

void loop() 
  val = analogRead(potpin);            // reads the value of the pot. and converts to digital value (value between 0 and 1023) 
  Serial.print("Val:");                // serial print the text "Val:"
  Serial.print(val);                   // serial print new line variable in Val
  angle = map(val, 0, 1023, 0, 180);   // does scaling for us (val - # to be scaled; 2nd/3rd - min/max ad conv; 4/5th - min/max servo)

  Serial.print(",Angle:");              // serial print the text "Angle:"
  Serial.println(angle);                 // serial print new line variable in Angle
  myServo.write(angle);                // sets the servo position according to the scaled value 

  delay(85);                           // waits for the servo to get there 

It wont compile as I don’t believe it can see the Servo2 library.

… and reports;

In file included from sketch_ServoTimer2_jun28a.ino:11:0:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:117:14: error: conflicting declaration ‘typedef bool boolean’
typedef bool boolean;
In file included from sketch_ServoTimer2_jun28a.ino:9:0:
C:\Users\andy.upton\Documents\Arduino\libraries\ServoTimer2/ServoTimer2.h:59:17: error: ‘boolean’ has a previous declaration as ‘typedef uint8_t boolean’
typedef uint8_t boolean;
Error compiling.

I definitely believe the Servotimer2.h is not recognised as a library by my arduino uno ...... if somebody could advise that would help me...

I added this library to arduino libraries as follows;

I downloaded the library Servotimer2.h as a Zip file. Then I added this zip file by clicking -> include library -> add ZIP library... and then selected the zip file servotimer2 and included it in my program.

I notice that the library is not accepted like other libraries (i.e. doesn't change colour!)

'boolean' has a previous declaration as 'typedef uint8_t boolean'
typedef uint8_t boolean;

I suspect you are using Arduino IDE 1.6.x which is not backwards compatible with some stuff.

Try using IDE 1.5.6 - because I don't know the fix for 1.6.x :slight_smile:

I have used this ServoTimer2 library without problems