Go Down

Topic: Trouble writing a library (Read 1 time) previous topic - next topic

alfiesty

I attempting to learn how to write libraries. It is just to learn and doesn't do much.
I have written a keyword  file. a .cpp file and a .h file all with the name THMOD.(H/txt/cpp). I put the three files in a directory arduino/library/THMOD. To test, I closed Arduino and re-opened it, and I created a sketch with just the line "#include "THMOD.H".  I get the message "sketch_feb19a.cpp:1:19: error: THMOD.H: No such file or directory". Do I need to compile the ccp file to a .o file and if so, with what program?
Jim
8000ft above the average

robtillaart


you can post the code of your libs and sample code.

A better place to put your libraries is in your code folder/libraries, see FILE-> preferences for the location.

Are you shure you killed all instances of the IDE?


Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

alfiesty



you can post the code of your libs and sample code.

A better place to put your libraries is in your code folder/libraries, see FILE-> preferences for the location.

Are you shure you killed all instances of the IDE?





I rebooted the computer!

h file

#######################
# This is keywords for THMOD library
#######################
#infdef THMOD_H
#define THMOD_H
#include <WProgram.h>

class THMOD
public:
{
   THMOD();
   ~THMOD();
   float readC();
   float readF();
   float readH();
}
#endif

keyword file

#######################
# Datatypes (KEYWORD 1)
#######################

#######################
# Methods (KEYWORD2)
#######################
THMOD KEYWORD1
readC KEYWORD2
readF KEYWORD2
readH KEYWORD2

cpp file

/* this is an attempt to learn how to write libraries
by putting a wrapper around the SHT1x library
with shorter names*/
#include <SHT1x.h>
#include <math.h>
#include "THMOD.h" // include declaration

#define dataPin  4   // DATA
#define clockPin 5   // SCK
float temp_c;
float temp_f;  float humidity;

//constructor
THMOD::THMOD()
{
   SHT1x sht1x(dataPin, clockPin);
}
//destructor
THMOD::~THMOD() // nothing needed

float THMOD::readC()
{
    temp_c = sht1x.readTemperatureC();
    return temp_c;
}

float THMOD::readF()
{
    temp_f = sht1x.readTemperatureF();
    return temp_f;
}

float THMOD::readH()
{
    humidity = sht1x.readHumidity();
    return humidity;
}

All this does is give me easier names because my right arm is amputated and typing with just your left hand is not easy.
Jim

8000ft above the average

robtillaart

Quote
All this does is give me easier names because my right arm is amputated and typing with just your left hand is not easy.

I understand, for me that would mean less than half the speed, maybe even 1/4 th.
This might be something for you - http://www.footmouse.com/ - to consider. Would enable you to copy and paste faster after some exercise.
(there are probably more footmouses from different suppliers)


If you use Arduino 1.0 you should use something like:

#if ARDUINO < 100
#include <WProgram.h>
#else
#include <Arduino.h>
#endif

I recall that using libraries in a library on the Arduino platform have some issues. Think you have to include
#include <SHT1x.h>
#include <math.h>
in your main sketch too.

Hope this helpes.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

alfiesty


Quote

If you use Arduino 1.0 you should use something like:

#if ARDUINO < 100
#include <WProgram.h>
#else
#include <Arduino.h>
#endif

I recall that using libraries in a library on the Arduino platform have some issues. Think you have to include
#include <SHT1x.h>
#include <math.h>
in your main sketch too.

Hope this helpes.



I am using 022 until I hear all the libraries are sorted out.
Putting includes in main sketch no help!
jim
8000ft above the average

Go Up