[SOLVED] How to use additional files (.c and .h) with .ino file (Particle desktop IDE)

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

A couple of things I see wrong. You should be importing your file, not the class ( #include MyFunctions.h not #include Morse.h). You should also #include Particle.h rather than Arduino.h, and normally, the implementation file should have a .cpp suffix rather than .c (though, I don’t know if that matters).

1 Like

Thanks @Ric - there were some typos in my original post, so I have updated those and included your suggestions, getting the same compile errors though.

Well that did it! Changed the 'MyFunctions.c' to 'MyFunctions.cpp' and now compiles.

Thank you - really appreciate your help @Ric.