creating a library

Hi, sorry if this is the most asked question on this board but had a good search and found nothing that applies.
So...
I'm trying to create a library to control a set of servos, I've gone through the tutorials a few times but still very stuck!
I have made the header --

#ifndef Move_h
#define Move_h
#include "WProgram.h"
class Move
{
  public:
  void up();
  private:
  float _l;
};
#endif

and cpp

#include "WProgram.h"
#include "Move.h"

void Move::up(){
for(float _l = 10; _l<90; _l=_l+1){
  servoL1.write(_l);
delay(100);
}
}

and finally my main program

#include <Move.h>
#include <Servo.h> 

Servo servoH1; 
Servo servoL1; 
Servo servoF1;

Move move;

void setup()
{
servoH1.attach(22);  
servoL1.attach(23);
servoF1.attach(25);
}
void loop(){
  move.up();
}

however i get the errors---
...\arduino-0022\libraries\Move\Move.cpp: In member function 'void Move::up()':
...\arduino-0022\libraries\Move\Move.cpp:7: error: 'servoL1' was not declared in this scope

I've played around with it for quite a while but cant work out where i need to define the servo and the other error i have no idea about?!
This is a simplified version of what im trying get to - once ive got libraries sorted im wanting to set the delay from the main program and in the cpp have functions which relate two servo positions to another, but for now im just looking to get one servo working!
Any help would be awesome, otherwise im going to have a monster code [20servos and 6routines!] on one page!
Thanks,
Andrew

Your problem is one of scope; your class can't "see" servoL1, so you must either change the scope, or "introduce" the servo object into your class.

Also, "Servo.write" does not take a float parameter; using one is simply a waste of processing time.

for(float _l = 10; _l<90; _l=_l+1){
  servoL1.write(_l);

The message is pretty obvious. In the Move class, in the up() function, you reference servoL1, but servoL1 is not defined anywhere.

Seems to be that the servo to move should be an input to the up() function.

firstly thanks for the replies,
do you mean i should specify the servo in the header? if so how do i actually do that? Will that mean i also need to include the servo.h in my ccp?
Sorry for being a massive noob, is only my 2nd week with arduino [and not much more for programming in general]
oh also i am using float because when ive got the other servos in their positions are calculated using a polynomial ive derived and so wont be integers. can servo definitely not take floats? ive been using them without a problem in other programs.
thanks again,
andrew

. can servo definitely not take floats?

You can give it a float, but it will simply convert (truncate) to an integer before the call.

aah ok, so much to learn!
would you have any more advice on where i need to declare the servos etc?
cheers,
andrew

Well, you need a method of associating the servo with your class (if that's what you want to do), so you could do that in your constructor, or a "begin" method.
You just need to pass a pointer to your servo object to whichever method you choose, and store a private pointer within your class.

could you show me how you mean? ive tried to add servoH1 in to the private section [not much of a pun intended] of the header but it gives me an error telling me its undefined or that 'begin' which i tried infront of the servoH1 'does not name a type'. i know how to define the voids, ints and floats but not a servo?
Cheers, Andrew

Something like:

class Move
{
  public:
  void up();
  void attach (Servo* s) {servo = s;}
  private:
  Servo* servo;
};
#include "WProgram.h"
#include "Move.h"

void Move::up(){
for(int _l = 10; _l<90; ++_l){
  servo->write(_l);
  delay(100);
}
}

hi,
firstly thanks for taking the time to help us out.
gave the code a fiddle with and played around with it for quite a while but still getting errors. Think i will have to return to the basic way of doing things as my coding for sure isnt up to scratch!
Thanks again,
Andrew

and played around with it for quite a while but still getting errors

If you post the code and the errors you're getting, we can help.

afraid im at work at the moment so dont cant get the errors etc, however its mainly not understanding the code you wrote thats causing me the problem really,
ok, so things i don't get -

where should i state the servo names and pins? should it be in my main program or do i also need to do it in the .cpp?

could you explain this - 'void attach (Servo* s) {servo = s;}', is it the same as my 'servoH1.attach(22); ' ? what are the * and s for?

Thanks very much for your help mate, i hopefully will learn alot from this problem!

Trying to keep it simple, the class needs a means of accessing the servo associated with it, and you need a means of associating the servo with the class.
So, the "Servo" declaration remains in the .pde, (incomplete, uncompiled, untested)

Servo elbowServo;
Move myMove;
void setup ()
{
  elbowServo.attach (elbowServoPin);
  myMove.attach (&elbowServo);  // now "myMove" has a way of accessing the servo.
}

void loop ()
{
  myMove.up ();
}  
}

"Servo* s" means "s is a pointer to a Servo"

awesome, that makes alot more sense to me.
so then in my .h file i would stick 'void attach elbowServo' in pulic and 'elbowServo = _elbowServo' in private?
Thanks,

so then in my .h file i would stick 'void attach elbowServo' in pulic and 'elbowServo = _elbowServo' in private?

I don't know what you're asking here - because the "attach" method is so short and simple, I put the implementation of it in the .h rather than the .cpp

ahh i see. ye that is much easier that way. sorted. will give that a whirl when i get home. also got a sharp ir range sensor today. going to have my brain in knots all night.
cheers

ok, so had another go. still nothing. getting massively confused by the pointers you are using. had a look in reference to try and work them out and it told me i have no chance as a beginner! is there any way to write the code without these pointers?
from what i understand so far - i state my servos and the pins they are attached to in my main program. then in my cpp i just tell it what i want it to do - ie myservo.write(90); or whatever?
thanks again
andrew

is there any way to write the code without these pointers?

Yes, but the whole concept of encapsulating the servo will be lost.

Perhaps it's time for you to post some current code, and summarize the issues you are having. It should not (and will not be next time) as difficult as you are making it sound.

hi,
got back to this after a little sanity break.... think ive realised where i was going wrong for the most part.
i want the program to move the servo on pin22 to 180deg and back to 0deg [as a building block for creating a more complicated library]
nb: I've copied this from the library tutorial for SOS light

here is my .h

#ifndef Move_h
#define Move_h

#include "WProgram.h"

class Move
{
public:
  Move(); 
  void forward();
  void back();
private:
  int _angle; // i dont actually need this yet, just wasn't sure if leaving private empty would cause a problem
};

#endif

...my .cpp

#include "WProgram.h"
#include "Move.h"
#include "Servo.h"

Servo servo1;

Move::Move()
{
  servo1.attach(22);
}

void Move::forward()
{
servo1.write(180);
}

void Move::back()
{
  servo1.write(0);
}

and my main program

#include <Move.h>

Move move();

void setup()
{
}

void loop(){
  move.forward();
  delay(1000);
  move.back();
  delay(1000);
}

however this gives me this error

move_lib_attempt2.cpp: In function 'void loop()':
move_lib_attempt2:9: error: request for member 'forward' in 'move', which is of non-class type 'Move ()()'
move_lib_attempt2:11: error: request for member 'back' in 'move', which is of non-class type 'Move ()()'

thought i had it cracked until i tested it. no idea what this error code means?
any help would be really awesome!
thanks
andrew

Get rid of the () when you construct your object-- it should just be

Move move;