Unable to compile 'softwareservo.h' sketch

Sorry about this-am real noob with this. Trying to verify softwareservo.h but keep getting error messages which I didn't think would be there as I haven't changed anything!

This is the code:

[quote]
[color=green]#include <SoftwareServo.h>

SoftwareServo servo1;
SoftwareServo servo2;

[color=#CC6600]void[/color] [color=#CC6600][b]setup[/b][/color]()
{
  [color=#CC6600]pinMode[/color](13,[color=#006699]OUTPUT[/color]);
  servo1.[color=#CC6600]attach[/color](2);
  servo1.setMaximumPulse(2200);
  servo2.[color=#CC6600]attach[/color](4);
  servo2.setMaximumPulse(2200);
  [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]begin[/color](9600);
  [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color]([color=#006699]"Ready"[/color]);
}

[color=#CC6600]void[/color] [color=#CC6600][b]loop[/b][/color]()
{
  [color=#CC6600]static[/color] [color=#CC6600]int[/color] value = 0;
  [color=#CC6600]static[/color] [color=#CC6600]char[/color] CurrentServo = 0;

  [color=#CC6600]if[/color] ( [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]available[/color]()) {
    [color=#CC6600]char[/color] ch = [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]read[/color]();
    [color=#CC6600]switch[/color](ch) {
      [color=#CC6600]case[/color] [color=#006699]'A'[/color]:
        servo1.[color=#CC6600]attach[/color](2);
        CurrentServo=[color=#006699]'A'[/color];
        [color=#CC6600]digitalWrite[/color](13,[color=#006699]LOW[/color]);
        [color=#CC6600]break[/color];
      [color=#CC6600]case[/color] [color=#006699]'B'[/color]:
        servo2.[color=#CC6600]attach[/color](4);
        CurrentServo=[color=#006699]'B'[/color];
        [color=#CC6600]digitalWrite[/color](13,[color=#006699]HIGH[/color]);
        [color=#CC6600]break[/color];
      [color=#CC6600]case[/color] [color=#006699]'0'[/color] ... [color=#006699]'9'[/color]:
        value=(ch-[color=#006699]'0'[/color])*20;
        [color=#CC6600]if[/color] (CurrentServo==[color=#006699]'A'[/color])
        {
          servo1.[color=#CC6600]write[/color](value);
        }
        [color=#CC6600]else[/color] [color=#CC6600]if[/color] (CurrentServo==[color=#006699]'B'[/color])
        {
          servo2.[color=#CC6600]write[/color](value);
        }
        [color=#CC6600]break[/color];
    }
  }
  SoftwareServo::refresh();
}

[/quote]

[/color]

This is the error messages?

SerialServo:3: error: 'SoftwareServo' does not name a type
SerialServo:4: error: 'SoftwareServo' does not name a type
SerialServo.pde: In function 'void setup()':
SerialServo:9: error: 'servo1' was not declared in this scope
SerialServo:11: error: 'servo2' was not declared in this scope
SerialServo.pde: In function 'void loop()':
SerialServo:26: error: 'servo1' was not declared in this scope
SerialServo:31: error: 'servo2' was not declared in this scope
SerialServo:48: error: 'SoftwareServo' has not been declared

Sorry again to bug you! =(

Could you post the code without the color tags?

Have you actually got the SoftwareServo library files ?
Which folder are they in ?
Is there a reason why you cannot use the normal Servo library ?

When you post your code again without the color tags please preview it to make sure that it can be read !

Thanks for helping. I'm not using reg servo library as I was going to use the virtual wire lib which doesn't play nice with servo lib. Location is in 'my documents\arduino.

[quote]
#include <SoftwareServo.h>

SoftwareServo servo1;
SoftwareServo servo2;

[color=#CC6600]void[/color] [color=#CC6600][b]setup[/b][/color]()
{
  [color=#CC6600]pinMode[/color](13,[color=#006699]OUTPUT[/color]);
  servo1.[color=#CC6600]attach[/color](2);
  servo1.setMaximumPulse(2200);
  servo2.[color=#CC6600]attach[/color](4);
  servo2.setMaximumPulse(2200);
  [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]begin[/color](9600);
  [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color]([color=#006699]"Ready"[/color]);
}

[color=#CC6600]void[/color] [color=#CC6600][b]loop[/b][/color]()
{
  [color=#CC6600]static[/color] [color=#CC6600]int[/color] value = 0;
  [color=#CC6600]static[/color] [color=#CC6600]char[/color] CurrentServo = 0;

  [color=#CC6600]if[/color] ( [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]available[/color]()) {
    [color=#CC6600]char[/color] ch = [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]read[/color]();
    [color=#CC6600]switch[/color](ch) {
      [color=#CC6600]case[/color] [color=#006699]'A'[/color]:
        servo1.[color=#CC6600]attach[/color](2);
        CurrentServo=[color=#006699]'A'[/color];
        [color=#CC6600]digitalWrite[/color](13,[color=#006699]LOW[/color]);
        [color=#CC6600]break[/color];
      [color=#CC6600]case[/color] [color=#006699]'B'[/color]:
        servo2.[color=#CC6600]attach[/color](4);
        CurrentServo=[color=#006699]'B'[/color];
        [color=#CC6600]digitalWrite[/color](13,[color=#006699]HIGH[/color]);
        [color=#CC6600]break[/color];
      [color=#CC6600]case[/color] [color=#006699]'0'[/color] ... [color=#006699]'9'[/color]:
        value=(ch-[color=#006699]'0'[/color])*20;
        [color=#CC6600]if[/color] (CurrentServo==[color=#006699]'A'[/color])
        {
          servo1.[color=#CC6600]write[/color](value);
        }
        [color=#CC6600]else[/color] [color=#CC6600]if[/color] (CurrentServo==[color=#006699]'B'[/color])
        {
          servo2.[color=#CC6600]write[/color](value);
        }
        [color=#CC6600]break[/color];
    }
  }
  SoftwareServo::refresh();
}

[/quote]

Error Messages:

C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=154 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard -IC:\Users\Dr. RMK\Documents\Arduino\libraries\SoftwareServo C:\Users\DR7308~1.RMK\AppData\Local\Temp\build8417295825100468320.tmp\SerialServo.cpp -o C:\Users\DR7308~1.RMK\AppData\Local\Temp\build8417295825100468320.tmp\SerialServo.cpp.o
C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=154 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard -IC:\Users\Dr. RMK\Documents\Arduino\libraries\SoftwareServo -IC:\Users\Dr. RMK\Documents\Arduino\libraries\SoftwareServo\utility C:\Users\Dr. RMK\Documents\Arduino\libraries\SoftwareServo\SoftwareServo.cpp -o C:\Users\DR7308~1.RMK\AppData\Local\Temp\build8417295825100468320.tmp\SoftwareServo\SoftwareServo.cpp.o
C:\Users\Dr. RMK\Documents\Arduino\libraries\SoftwareServo\SoftwareServo.cpp: In member function 'uint8_t SoftwareServo::attach(int)':
C:\Users\Dr. RMK\Documents\Arduino\libraries\SoftwareServo\SoftwareServo.cpp:27: error: 'digitalWrite' was not declared in this scope
C:\Users\Dr. RMK\Documents\Arduino\libraries\SoftwareServo\SoftwareServo.cpp:28: error: 'OUTPUT' was not declared in this scope
C:\Users\Dr. RMK\Documents\Arduino\libraries\SoftwareServo\SoftwareServo.cpp:28: error: 'pinMode' was not declared in this scope
C:\Users\Dr. RMK\Documents\Arduino\libraries\SoftwareServo\SoftwareServo.cpp: In member function 'void SoftwareServo::write(int)':
C:\Users\Dr. RMK\Documents\Arduino\libraries\SoftwareServo\SoftwareServo.cpp:51: error: 'clockCyclesPerMicrosecond' was not declared in this scope
C:\Users\Dr. RMK\Documents\Arduino\libraries\SoftwareServo\SoftwareServo.cpp: In static member function 'static void SoftwareServo::refresh()':
C:\Users\Dr. RMK\Documents\Arduino\libraries\SoftwareServo\SoftwareServo.cpp:73: error: 'millis' was not declared in this scope
C:\Users\Dr. RMK\Documents\Arduino\libraries\SoftwareServo\SoftwareServo.cpp:106: error: 'digitalWrite' was not declared in this scope
C:\Users\Dr. RMK\Documents\Arduino\libraries\SoftwareServo\SoftwareServo.cpp:108: error: 'TCNT0' was not declared in this scope
C:\Users\Dr. RMK\Documents\Arduino\libraries\SoftwareServo\SoftwareServo.cpp:123: error: 'digitalWrite' was not declared in this scope

SerialServo:3: error: 'SoftwareServo' does not name a type
SerialServo:4: error: 'SoftwareServo' does not name a type

These errors usually indicate that the library files are not installed in the correct folder. The files for the SoftwareServo library should be in 'my documents\arduino\libraries\SoftwareServo'

You have posted your code littered with colour tags again which makes it practically unreadable. Did you not preview your post as I suggested ?

Sorry bout color, not sure what happened? Trying again-thanks for the time.

#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();
}

Error Messages:

Arduino: 1.5.4 (Windows 7), Board: "Arduino Uno"

C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=154 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard -IC:\Users\Dr. RMK\Documents\Arduino\libraries\SoftwareServo C:\Users\DR7308~1.RMK\AppData\Local\Temp\build8417295825100468320.tmp\SerialServo.cpp -o C:\Users\DR7308~1.RMK\AppData\Local\Temp\build8417295825100468320.tmp\SerialServo.cpp.o

C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=154 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard -IC:\Users\Dr. RMK\Documents\Arduino\libraries\SoftwareServo -IC:\Users\Dr. RMK\Documents\Arduino\libraries\SoftwareServo\utility C:\Users\Dr. RMK\Documents\Arduino\libraries\SoftwareServo\SoftwareServo.cpp -o C:\Users\DR7308~1.RMK\AppData\Local\Temp\build8417295825100468320.tmp\SoftwareServo\SoftwareServo.cpp.o

C:\Users\Dr. RMK\Documents\Arduino\libraries\SoftwareServo\SoftwareServo.cpp: In member function 'uint8_t SoftwareServo::attach(int)':
C:\Users\Dr. RMK\Documents\Arduino\libraries\SoftwareServo\SoftwareServo.cpp:27: error: 'digitalWrite' was not declared in this scope
C:\Users\Dr. RMK\Documents\Arduino\libraries\SoftwareServo\SoftwareServo.cpp:28: error: 'OUTPUT' was not declared in this scope
C:\Users\Dr. RMK\Documents\Arduino\libraries\SoftwareServo\SoftwareServo.cpp:28: error: 'pinMode' was not declared in this scope
C:\Users\Dr. RMK\Documents\Arduino\libraries\SoftwareServo\SoftwareServo.cpp: In member function 'void SoftwareServo::write(int)':
C:\Users\Dr. RMK\Documents\Arduino\libraries\SoftwareServo\SoftwareServo.cpp:51: error: 'clockCyclesPerMicrosecond' was not declared in this scope
C:\Users\Dr. RMK\Documents\Arduino\libraries\SoftwareServo\SoftwareServo.cpp: In static member function 'static void SoftwareServo::refresh()':
C:\Users\Dr. RMK\Documents\Arduino\libraries\SoftwareServo\SoftwareServo.cpp:73: error: 'millis' was not declared in this scope
C:\Users\Dr. RMK\Documents\Arduino\libraries\SoftwareServo\SoftwareServo.cpp:106: error: 'digitalWrite' was not declared in this scope
C:\Users\Dr. RMK\Documents\Arduino\libraries\SoftwareServo\SoftwareServo.cpp:108: error: 'TCNT0' was not declared in this scope
C:\Users\Dr. RMK\Documents\Arduino\libraries\SoftwareServo\SoftwareServo.cpp:123: error: 'digitalWrite' was not declared in this scope

SoftwareServo.h contains this:

#include <WProgram.h>
#include <inttypes.h>

:That means that the library has not been updated for 1.0+ use. You can change WProgram.h to Arduino.h

I've done as suggested but still get stuck on errors:

#include <Servo.h> 

Servo servo1;

#define irPin 0
#define pwrPin 3
#define soundPin 8
#define servoPin 9

void setup() { 
  //Pin setup
  pinMode(pwrPin, OUTPUT);
  pinMode(soundPin, OUTPUT);
  digitalWrite(pwrPin, HIGH);
  digitalWrite(soundPin, LOW);

    
  //Servo setup
  servo.attach(servoPin);
  reset_servo();
  digitalWrite(13, HIGH);
  delay(60000);
  digitalWrite(13, LOW);
} 

void loop(){
  int count = 0;
  while(analogRead(irPin) > 80){
    if(count > 5){
      shoot_string(30);
      play_sound();
      reset_servo();
      digitalWrite(13, HIGH);
      delay(20000);
      digitalWrite(13, LOW);
    }
    count++;
    delay(10);
  }
  delay(10);
} 

void shoot_string(int shoot_time){
  for(int i = 0; i < shoot_time; i++){
      servo.write(90);
      delay(10);
      SoftwareServo::refresh();
  }
}

void reset_servo(){
  int return_time = 100;
  for(int i = 0; i < return_time; i++){
      servo.write(0);
      delay(10);
      SoftwareServo::refresh();
   }
}

void play_sound(){
  digitalWrite(soundPin, HIGH);
  delay(100);
  digitalWrite(soundPin, LOW);
}

Error message:
Arduino: 1.5.4 (Windows 7), Board: "Arduino Uno"

C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=154 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard -IC:\Users\Dr. RMK\Documents\Arduino\libraries\Servo C:\Users\DR7308~1.RMK\AppData\Local\Temp\build1218140715630769991.tmp\SillyStringShooter2.cpp -o C:\Users\DR7308~1.RMK\AppData\Local\Temp\build1218140715630769991.tmp\SillyStringShooter2.cpp.o

SillyStringShooter2.pde: In function 'void setup()':
SillyStringShooter2:19: error: 'servo' was not declared in this scope
SillyStringShooter2.pde: In function 'void shoot_string(int)':
SillyStringShooter2:45: error: 'servo' was not declared in this scope
SillyStringShooter2:47: error: 'SoftwareServo' has not been declared
SillyStringShooter2.pde: In function 'void reset_servo()':
SillyStringShooter2:54: error: 'servo' was not declared in this scope
SillyStringShooter2:56: error: 'SoftwareServo' has not been declared

download the latest version of the IDE and install it. It wont over write an sketches you have and try again.

Mark

I have done that-version 1.5.4 for windows! It still won't compile? Thanks for trying to help me. Not easy being a moron! =(

robertmkmd:
I've done as suggested but still get stuck on errors:

'servo1' is not the same spelling as 'servo'.

Compare this line:
Servo servo1;

To this:
servo.attach(servoPin);

Notice that they are not the same variable?


You are also using this in your code:

SoftwareServo::refresh();

But you are now using the Servo library, not the SoftwareServo library so is it any wonder it won't compile that.