declaring multiple pins on include libraries

Hi, Im new on arduino and I have an issue. I need to create a library that uses at least 3 pins and the help on creating libraries shows how to create one pin only. How can I declare several pins to a library from the sketch section?.. And finaly how can I declare variables to use on the library?..

I presume that you have seen this http://arduino.cc/en/Hacking/LibraryTutorial

Using that as a base I had no problem creating a library to control a motor shield that took 3 pin numbers as arguments, like the LCD library, which uses several. Just pass the pin numbers to the library as arguments to a library function as you would for any other function.

What sort of variables do you have in mind ?

Examples from my motor control library
part of bbMotor.h

#ifndef bbMotor_h
#define bbMotor_h

#include "Arduino.h"

class bbMotor
{
	public:
		bbMotor(int enable, int input_1_pin, int input_2_pin);
		void begin();
		void setSpeed(int speed);
		int getSpeed();
	private:
		int _enable;
		int _input_1_pin;
		int _input_2_pin;
		int _speed;
};

#endif

Part of bbMotor.cpp

#include "Arduino.h"
#include "bbMotor.h"

bbMotor::bbMotor(int enable, int input_1_pin, int input_2_pin)
{
	_enable = enable;
	_input_1_pin = input_1_pin;
	_input_2_pin = input_2_pin;
}

void bbMotor::begin()	//pinMode may not work if called in constructor, so use this
{
	pinMode(_enable, OUTPUT);
	pinMode(_input_1_pin, OUTPUT);
	pinMode(_input_2_pin, OUTPUT);
	digitalWrite(_enable, LOW);
}

int bbMotor::getSpeed()
{
	return _speed;
}

An example of creating 2 instances of bbMotor

bbMotor leftMotor(6,8,7);  //enable (PWM), InA, InB
bbMotor rightMotor(3,2,4);  //enable (PWM), InA, InB

Setting up a motor. Done in setup() rather than in the constructor to ensure that hardware is ready for pinMode()

  leftMotor.begin();

Setting the speed of a motor

    leftMotor.forward(100);

Getting the current speed of a motor

currentSpeed = leftMotor.getSpeed()

I hope this helps

tanaris12: perhaps I was not clear on my doubt.

The reference only shows one pin that declares as Morse morse(13); when calling the library, how do I declare more than just one pin and how do I link variables to the library from the sketch? is it Morse morse1..2..3..n(); in the case of the example for the pins? and whats the proper coding for linking variables are they declared on the sketch or the library?

I have many years of experience on c programing but I need to know how its done on this language since the syntax is different. The variables I need are integers and an array.

Note, it may be that the Morse library is the one I downloaded some time ago, and it is badly written. It does not store the pin values in the constructor within the class, instead it has static variables in Morse.cpp that it copies the values into, so you can only have one device. For my steampunk camera, at times I wanted to generate Morse code for 'Fire' when I trigger the camera. I wanted an option to do either blinky lights or via a buzzer, and control it via a dip switch. I've been meaning to rewrite it so it stores the pin values within the class (so I can have a light morse target and a buzzer one), and also remove the delays, and rewrite it to use blink without delay, so the Arduino is not locked up when doing the morse sequence.

And Im left with no answer at all.

The motor shield code does not say anything on how to do what I need because its incomplete but thanks for trying any ways.

The motor shield code I posted has an example of creating an instance of an object and passing 3 pin numbers to it

bbMotor leftMotor(6,8,7);

It has an example of passing a value to an instance of the object

leftMotor.forward(100);

Variables to be passed to the library object are declared in the normal way The example could just as well be

int speed = 100;
leftMotor.forward(speed);

It has an example of passing a variable from an object to the main code

currentSpeed = leftMotor.getSpeed()

Is that not what you want ?

I am sorry that you are

left with no answer at all.

Can you explain another way what it is you need to know ?

ok so how do you separate the pins to use with different data on each one of them on the library?

You should probably head over to cplusplus.com and read the tutorial on classes (http://cplusplus.com/doc/tutorial/classes/). In fact you should probably read the tutorials from the start.

When you get a grip on how to handle object oriented programming your problem will become simpler. I think this is one of those things where examples won't help much without knowledge of the underlying concepts.

and that simple answer could not be given thanks for trying

You've been given examples of how to pass multiple values to a function. What is it about that that you are having issues with?

Ill try my luck on another place and dont worry about this post ill leave it there but dont reply dont want to consume any of your time on insignificant issues like mine

Not everyone "gets it" the same way. Different perspectives are sometimes useful. If you don't like a response, YOU can ignore it, too.

You were already offered very clear examples of the syntax. If you didn't understand them it's because you don't grasp the concept. That tutorial I linked to clearly shows how to define an object and how to pass arguments to the constructor (complete with proper syntax). All you need to do is pass the pin values to the constructor when you instance your object. However, with Arduino you don't want to initialize the pins in the constructor you want to have a begin method called during setup.

If you are clear on the concept that's all you should need to know. I think you should read the tutorial. In about an hour all that would make sense. Including the syntax.