Morse code not working

I was trying to make a very simple Library, following the instructions on :
https://www.arduino.cc/en/Hacking/LibraryTutorial

So, have created the .h file:

/*
  Morse.h - Library for flashing Morse code.
  Created by David A. Mellis, November 2, 2007.
  Released into the public domain.
*/

#ifndef Morse_h
#define Morse_h
#include "Arduino.h"

class Morse
{
public:
Morse(int pin);
void dot();
void dash();

private:
int _pin;

}

#endif

…the .cpp file:

#include "Arduino.h"
#include "Morse.h"

Morse::Morse(int pin)
{
  
pinMode(pin, OUTPUT);
_pin=pin;
}

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);
}

Wrote the .ino file that uses the Library:

#include <Morse.h>
Morse morse(13);
void setup() {

  // put your setup code here, to run once:

}

void loop() {
 morse.dot(); morse.dot(); morse.dot();
 
  delay(3000);
}

…saved the .h & .cpp file in my “…Arduino/libraries/” folder, as suggested and the .ino where my files are but when trying to upload the code to Arduino UNO, I get:

myMorse:10: error: ‘morse’ was not declared in this scope

morse.dot(); morse.dot(); morse.dot();

^

exit status 1
expected initializer before ‘morse’

…any suggestions?

Did you stop/start the IDE after installing the library files ?

you have to put a semicolon after the definition of a class…

see here:

/*
  Morse.h - Library for flashing Morse code.
  Created by David A. Mellis, November 2, 2007.
  Released into the public domain.
*/

#ifndef Morse_h
#define Morse_h
#include "Arduino.h"

class Morse
{
public:
Morse(int pin);
void dot();
void dash();

private:
int _pin;

};  //  <<<<<<<<<<<<<<<<<<<  RIGHT HERE!!!

#endif

You've got to be kidding me!

ok, added the missing semicolon but when compiling I receive the following:

In file included from sketch\Morse\Morse.cpp:2:0:

sketch\Morse\Morse.h:11:1: error: new types may not be defined in a return type

class Morse

^

sketch\Morse\Morse.h:11:1: note: (perhaps a semicolon is missing after the definition of 'Morse')

sketch\Morse\Morse.cpp:4:21: error: return type specification for constructor invalid

Morse::Morse(int pin)

^

exit status 1
Error compiling.

what is heppening?

It compiled for me. IDE 1.6.5

I have the 1.6.7 version...
But why wouldn't it compile?

Any chance you didn't restart the IDE after adding the semi-colon?

Looks like it might be treating your whole class definition as the return type of Morse::Morse(). Which is going to be quite confusing to the compiler as well.

arduino_mike:
You've got to be kidding me!

That's the way the language works. Like, you put a period at the end of a sentence.

If you are getting more compile errors, please post your amended code.

Paul_Martinsen:
Any chance you didn't restart the IDE after adding the semi-colon?

Looks like it might be treating your whole class definition as the return type of Morse::Morse(). Which is going to be quite confusing to the compiler as well.

Also to the user. init() or begin() or something like that would be more appropriate for what it does.

The semicolon is needed because you can add variables right after the class definition:

class Example { ... } var1, var2;

ok, Solved.
I had placed the .h and .cpp files folder everywhere, with different signatures confusing me and the compiler. If as claimed you create a folder with the afore-mentioned files in libraries, everything works as expected.

Actually I didn't expect this semicolon to be the problem I thought it was a typo of the writer...

Thanx anyway, you've been most helpful.