Im making my own library and i want it so that it has more than 1 functions?
pls help
Im making my own library and i want it so that it has more than 1 functions?
pls help
So what's the problem?
We can't see your code and we have no idea what is going wrong. How are we to help.
Read the how to use this forum-please read sticky to see how to, properly, post code. Remove useless white space and format the code with the IDE autoformat tool (crtl-t or Tools, Auto Format) before posting code.
What problems are you having ?
Have you tried looking at some other libraries ?
How about posting your .h and .cpp files ?
groundFungus:
We can't see your code and we have no idea what is going wrong. How are we to help.Read the how to use this forum-please read sticky to see how to, properly, post code. Remove useless white space and format the code with the IDE autoformat tool (crtl-t or Tools, Auto Format) before posting code.
Sry im new here you go:
#include "Arduino.h"
#include "ServoGrid.h"
void Middle(){
servo1.write(90);
servo2.write(90);
}
void Up(){
servo1.write(180);
servo2.write(90);
}
void Down(){
servo1.write(0);
servo2.write(90);
}
void Left(){
servo1.write(90);
servo2.write(180);
}
void Right(){
servo1.write(90);
servo2.write(0);
}
UKHeliBob:
What problems are you having ?Have you tried looking at some other libraries ?
How about posting your .h and .cpp files ?
here you go:
/This is where you write the code you want to run/
#include "Arduino.h"
#include "ServoGrid.h"
void Middle(){
servo1.write(90);
servo2.write(90);
}
void Up(){
servo1.write(180);
servo2.write(90);
}
void Down(){
servo1.write(0);
servo2.write(90);
}
void Left(){
servo1.write(90);
servo2.write(180);
}
void Right(){
servo1.write(90);
servo2.write(0);
}
Also I have no idea what to put in the header file.
This is just experimental so I'm definitely going to change it in the near future!
And, yes I have but didn't really understand it.(probably because it was made by pros. )
One more thing, what should I put in the Header file.
thx!
I hope this helps somewhat. Here is a very simple class that IO hope helps you understand.
Headers are for declaring your function (Function ProtoType). The CPP files are for implementing your Functions.
Header
#include <Arduino.h>
class TestArduinoLib
{
public:
TestArduinoLib(byte pin);
~TestArduinoLib();
void Blink(unsigned int wait);
private:
byte _pin;
};
CPP File
#include "TestArduinoLib.h"
TestArduinoLib::TestArduinoLib(byte pin)
{
_pin = pin;
}
TestArduinoLib::~TestArduinoLib()
{
}
void TestArduinoLib::Blink(unsigned int wait)
{
pinMode(_pin, OUTPUT);
digitalWrite(_pin, HIGH);
delay(wait);
digitalWrite(_pin, LOW);
pinMode(_pin, INPUT);
}
Romonaga:
I hope this helps somewhat. Here is a very simple class that IO hope helps you understand.Headers are for declaring your function (Function ProtoType). The CPP files are for implementing your Functions.
Header
#include <Arduino.h>
class TestArduinoLib
{
public:
TestArduinoLib(byte pin);
~TestArduinoLib();
Blink(unsigned int wait);
private:
byte _pin;
};
CPP File
#include "TestArduinoLib.h"
TestArduinoLib::TestArduinoLib(byte pin)
{
_pin = pin;
}
TestArduinoLib::~TestArduinoLib()
{
}
TestArduinoLib::Blink(unsigned int wait)
{
pinMode(_pin, OUTPUT);
digitalWrite(_pin, HIGH);
delay(wait);
digitalWrite(_pin, LOW);
pinMode(_pin, INPUT);
}
oohhhh so headers are basically wat the user will be typing when they use it!
TestArduinoLib::Blink(unsigned int wait)
what is the "unsigned int wait"
and can i make multiple functions with this? (I just started but I'm good at changing code (: )
Yes, you can have many functions inside a class.
The unsigned in wait is a variable that I am passing into the function Blink. I use that for the delay time.
So to add a new function, you would add the function declaration inside the header and do the implementation of that function in the CPP. Examine the Blink Function.
Romonaga:
Yes, you can have many functions inside a class.The unsigned in wait is a variable that I am passing into the function Blink. I use that for the delay time.
So to add a new function, you would add the function declaration inside the header and do the implementation of that function in the CPP. Examine the Blink Function.
but what will i type to use it.
Thanks anyways
Here is how you would use the class.
#include "TestArduinoLib.h"
TestArduinoLib test(13);
void setup()
{
// put your setup code here, to run once:
}
void loop()
{
test.Blink(1000);
}