Problems using VirtualWire.h and Servo.h ( the sharing of the same timer)

Hello ,
i have problems using these libraries together , i tried using SoftwareServo.h instead of Servo.h , fixed the first error (changing #include <WProgram.h>) but i am still getting errors just on the included example (SerialServo)
The errors are :

Arduino: 1.6.7 (Windows 8.1), Board: “Arduino/Genuino Uno”

C:\Program Files (x86)\Arduino\libraries\SoftwareServo\SoftwareServo.cpp: In member function ‘uint8_t SoftwareServo::attach(int)’:

C:\Program Files (x86)\Arduino\libraries\SoftwareServo\SoftwareServo.cpp:27:23: error: ‘digitalWrite’ was not declared in this scope

digitalWrite(pin,0);

^

C:\Program Files (x86)\Arduino\libraries\SoftwareServo\SoftwareServo.cpp:28:17: error: ‘OUTPUT’ was not declared in this scope

pinMode(pin,OUTPUT);

^

C:\Program Files (x86)\Arduino\libraries\SoftwareServo\SoftwareServo.cpp:28:23: error: ‘pinMode’ was not declared in this scope

pinMode(pin,OUTPUT);

^

C:\Program Files (x86)\Arduino\libraries\SoftwareServo\SoftwareServo.cpp: In member function ‘void SoftwareServo::write(int)’:

C:\Program Files (x86)\Arduino\libraries\SoftwareServo\SoftwareServo.cpp:51:51: error: ‘clockCyclesPerMicrosecond’ was not declared in this scope

pulse0 = (min1616LclockCyclesPerMicrosecond() + (max16-min16)(16LclockCyclesPerMicrosecond())*angle/180L)/64L;

^

C:\Program Files (x86)\Arduino\libraries\SoftwareServo\SoftwareServo.cpp: In static member function ‘static void SoftwareServo::refresh()’:

C:\Program Files (x86)\Arduino\libraries\SoftwareServo\SoftwareServo.cpp:73:30: error: ‘millis’ was not declared in this scope

unsigned long m = millis();

^

C:\Program Files (x86)\Arduino\libraries\SoftwareServo\SoftwareServo.cpp:106:60: error: ‘digitalWrite’ was not declared in this scope

for ( i = 0; i < count; i++) digitalWrite( s*->pin, 1);*

  • ^*
    C:\Program Files (x86)\Arduino\libraries\SoftwareServo\SoftwareServo.cpp:108:21: error: ‘TCNT0’ was not declared in this scope
  • uint8_t start = TCNT0;*
  • ^*
    C:\Program Files (x86)\Arduino\libraries\SoftwareServo\SoftwareServo.cpp:123:28: error: ‘digitalWrite’ was not declared in this scope
    _ digitalWrite( s*->pin,0);_
    _
    ^_
    exit status 1
    Error compiling.
    _
    This report would have more information with*_
    * “Show verbose output during compilation”*
    * enabled in File > Preferences.*
    hope that i am posting in the right spot in the forum , i am new to this
    and thanks to anyone who is willing to help

You modified SoftwareServo.h or SoftwareServo.cpp or both, and posted no code. The modified code failed to compile, and you want us to explain why. Well, OK. You did something wrong.

Exactly what we do not know, because you did not POST YOUR CODE.

Did you "fix" the error by removing the #include?? (If so if you remove all the rest of the code you'll see it compiles probably fine :slight_smile: )

I did not remove the #include , i replaced it with #include “Arduino.h” instead of #include <WProgram.h> , the solution was noted here

as for the code it’s the example code that comes with the library
and here it is:
#include <SoftwareServo.h>

SoftwareServo servo1;
SoftwareServo servo2;

void setup()
{
pinMode(13,OUTPUT);
servo1.attach(2);
servo1.setMaximumPulse(2200);
servo2.attach(4);
servo2.setMaximumPulse(2200);
Serial.begin(9600);
Serial.print(“Ready”);
}

void loop()
{
static int value = 0;
static char CurrentServo = 0;

if ( Serial.available()) {
char ch = Serial.read();
switch(ch) {
case ‘A’:
servo1.attach(2);
CurrentServo=‘A’;
digitalWrite(13,LOW);
break;
case ‘B’:
servo2.attach(4);
CurrentServo=‘B’;
digitalWrite(13,HIGH);
break;
case ‘0’ … ‘9’:
value=(ch-‘0’)*20;
if (CurrentServo==‘A’)
{
servo1.write(value);
}
else if (CurrentServo==‘B’)
{
servo2.write(value);
}
break;
}
}
SoftwareServo::refresh();
}

PaulS:
You modified SoftwareServo.h or SoftwareServo.cpp or both

the only change that i made is changing the #include <WProgram.h> to #include “Arduino.h”

Did you install the code as a library or did you install the 2 files in your sketch?

I just created as small sketch with the 2 files from the library and your example code just above - so 3 files in the sketch - and I just modified the angle brackets

#include <SoftwareServo.h>

to read

#include "SoftwareServo.h"

because it’s a local file (and of course changed #include <WProgram.h> to #include “Arduino.h”

→ all compiles fine with the current version of the IDE. did not test of course if it does what you want

It worked !
Thank You very much for your Time and help , and i apologize if i caused any problems , as it is my first ever post

perfect! have fun