I have attempted to create my own library. I have several non-void functions i use regularly for various sketches and rather than including them in every sketch i just wanted to make a library. I am having trouble with what i am supposed to do with the constructor and destructor functions in the .cpp file. I have been working off of a template online that said to use this as the setup code for my other functions, but i do not need any external setup code other than starting the serial monitor. Are non-void functions incompatible with the library setup? thanks for any help.
Hi,
Welcome to the Forum
Post your library codes and we can tell you what you can to to get it working.
Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html
then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.
Tom.....
Are non-void functions incompatible with the library setup?
Like Serial.read()?
Is it just some functions not c++ objects? 'Cause that's what it sounds like.
If so here's an example.
Main prigram :
#include "incint.h"
int i;
void setup() {
Serial.begin(9600);
i = 0;
}
void loop() {
i = incInt(i);
Serial.println(i);
delay(500);
}
your .h file :
#ifndef INCINT_H
#define INCINT_H
int incInt(int inNum);
#endif
your .cpp file :
#include "incInt.h"
int incInt(int inNum) {
return inNum + 1;
}
That's all you need to do. Put the .h & .cpp into a folder, drop it in your librarys folder change the "...h". to <...h> and your good to go.
Hope this helps.
-jim lee