Dear community,
I'm new to the arduino board and have no experience in c++. I'm currently trying to learn how to write a custom library. However, I'm running into some problems when including libraries in my own custom library. I think I'm doing something wrong when calling the LiquidCrystal library. The main question is: How to I call my libraries properly?
What I want to archive:
I have a LCD screen and a I2C device. I want to write a custom library which includes the LiquidCrystal and Wire libraries. Also, these libraries have to be available for use in the main program.
Main program:
#include <LiquidCrystal.h>
#include <Wire.h>
#include "customLib.h"
customLib customlib;
void setup()
{
customlib.identify();
}
void loop()
{
lcd.setCursor(0, 1);
lcd.print("I am main program");
}
customLib header:
#ifndef customLib_h
#define customLib_h
#include "Arduino.h"
class Wire;
class LiquidCrystal;
class customLib
{
public:
customLib();
void identify();
private:
};
#endif
customLib cpp file:
#include "Arduino.h"
#include "customLib.h"
#include <LiquidCrystal.h>
#include <Wire.h>
LiquidCrystal lcd(4, 5, 6, 7, 8, 9, 10);
customLib::customLib()
{
lcd.begin(16,2);
}
void customLib::identify()
{
lcd.clear();
lcd.print("I am customLib");
}
Note: all this code is stripped down to the bare minimum I needed to describe my problem
When I compile this, it gives the error 'lcd was not declared in this scope'. This makes sense, as I've declared lcd in customLib.cpp. However, when I declare lcd in the main program, it will give the same error. This also makes sense, as I've now declared lcd in the main program, and not in the customLib.cpp. This brings us to the main question, How to I call my libraries properly?
Using the wire library gives no problems. I think this is because it doesn't need to be declared (e.g. no 'Wire wire;') in the code.
Thanks for your time, and I hope you can help me in understanding the Arduino code.
Used websites:
http://provideyourown.com/2011/advanced-arduino-including-multiple-libraries/