So I have a bunch of common functions that I want to break out into a re-usable class, but I don’t want to go through the pain of creating an official library and publishing it to the community (yet).
I have followed the tutorial here to get a basic grasp on how .c and .h file structure works;
https://www.arduino.cc/en/Hacking/LibraryTutorial
So my project structure looks as follows;
/src/MyApp.ino
/src/MyFunctions.h
/src/MyFunctions.c
/project.properties
/README.md
Content of MyApp.ino
#include <MyFunctions.h>
MyFunctions morse(13);
void setup()
{
}
void loop()
{
morse.dot();
}
Content of MyFunctions.h
#ifndef MyFunctions_h
#define MyFunctions_h
#include "Particle.h"
class MyFunctions
{
public:
MyFunctions(int pin);
void dot();
void dash();
private:
int _pin;
};
#endif
Content of MyFunctions.c
#include "Particle.h"
#include "MyFunctions.h"
MyFunctions::MyFunctions(int pin)
{
pinMode(pin, OUTPUT);
_pin = pin;
}
void MyFunctions::dot()
{
digitalWrite(_pin, HIGH);
delay(250);
digitalWrite(_pin, LOW);
delay(250);
}
void MyFunctions::dash()
{
digitalWrite(_pin, HIGH);
delay(1000);
digitalWrite(_pin, LOW);
delay(250);
}
When I compile (in the cloud) I get the following error;
When I delete MyFunctions.h and MyFunctions.c and remove the line;
#include <Morse.h>
from MyApp.ino it compiles fine.
Learning C++ has it’s trips, but there seems to be additional layers of complexity/restrictions/rigidity due to the Arduino sketch format and the Particle platform which are not obvious nor trivial.
Can anyone please help out a n00b here?
EDIT : fixed formatting
EDIT2 : updated with first suggestions and corrected a few code mistakes