yeah, in that example they are initializing the hardware (i.e. pinMode) in the constructor, which is not reliable.
this should work and be a better model for you.
class Morse
{
public:
Morse(int pin);
void begin();
void dot();
void dash();
private:
int _pin;
};
Morse::Morse(int pin) // constructor - this one takes exactly one parameter
{
//pinMode(pin, OUTPUT);
_pin = pin;
}
void Morse::begin() // definition of member function, note the namespace notation
{
pinMode(_pin, OUTPUT);
}
void Morse::dot()
{
digitalWrite(_pin, HIGH);
delay(250);
digitalWrite(_pin, LOW);
delay(250);
}
void Morse::dash()
{
digitalWrite(_pin, HIGH);
delay(1000);
digitalWrite(_pin, LOW);
delay(250);
}
Morse myObject(13); // calling the constructor with the on-board pin as its argument
void setup()
{
myObject.begin();
}
void loop()
{
myObject.dot(); myObject.dot(); myObject.dot(); // S
myObject.dash(); myObject.dash(); myObject.dash(); // O
myObject.dot(); myObject.dot(); myObject.dot(); // S
delay(3000);
}
my advice is to develop your class in your .ino file (as I showed you here). Then, when when it works the way you want, decide if you need it to actually be a library. If it is never used on another project, well, you don't need a library.
Knowing how classes work is an important next step. Get familiar with that in simple examples like the Morse thingy, first. It shows you how to set up a constructor, private and public class members and (like you learned) when to properly set up the hardware!!