first library need a set of eyes

Hello, I tried a few examples for making custom libraries. I have not had one work successfully. I am not sure what I am missing. I have been over the example a few times. I have them loaded in the ardunio library folder. I included it in the example from the tab, not typing it in.

#include <Flasher.h>


const int ledPin = 13;
const int slowDuration =300;
const int fastDuration = 100;

Flasher slowFlasher (ledPin, slowDuration);
Flasher fastFlasher (ledPin, fastDuration);
void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:
slowFlasher.flash (5);
delay (1000);
fastFlasher.flash(10);
delay(2000);
}

error code

C:\Users\AudiP\Documents\Arduino\libraries\Flasher\Flasher.cpp:3:40: warning: declaration of 'Flasher::Flasher(int, int)' outside of class is not definition [-fpermissive]

 Flasher::Flasher (int pin, int duration);//prefix Flasher: indicates methoid belongs to Flasher class

                                        ^

C:\Users\AudiP\Documents\Arduino\libraries\Flasher\Flasher.cpp:4:1: error: expected unqualified-id before '{' token

 {

 ^

C:\Users\AudiP\Documents\Arduino\libraries\Flasher\Flasher.cpp:9:33: error: no 'void Flasher::flasher(int)' member function declared in class 'Flasher'

 void Flasher::flasher (int times);//prefix Flasher: indicates methoid belongs to Flasher class

                                 ^

C:\Users\AudiP\Documents\Arduino\libraries\Flasher\Flasher.cpp:10:1: error: expected unqualified-id before '{' token

 {

 ^

exit status 1
Error compiling for board Arduino/Genuino Uno.

.h file

//led flashing libarary
#include "arduino.h"
class Flasher
{
public: //contains methoids
Flasher(int pin,int duration); //this is a methoid. called a constructor. beging with uppercase.
void flash(int times); //this is the second methoid.
private:// contains variable definions. called member variables.ex _pin or mpin
int _pin; //define the pin nnumber
int _d; //define the duration
};

.cpp

#include "Flasher.h"

Flasher::Flasher (int pin, int duration);//prefix Flasher: indicates methoid belongs to Flasher class
{
	pinMode (pin, OUTPUT);
	_pin = pin;
	_d = duration / 2; // devide by two because there are two delays
}
void Flasher::flasher (int times);//prefix Flasher: indicates methoid belongs to Flasher class
{
	for (int i = 0; i < times; i++) //loop until i is = to times
	{
		digitalWrite (_pin, HIGH);
		delay (_d);
		digitalWrite (_pin, LOW);
		delay (_d);
	}
}
Flasher::Flasher (int pin, int duration);//prefix Flasher

There should NOT be a ; jammed in there. There SHOULD be spaces before and after the comment symbol.

turbonasty:
.h file

void flash(int times); //this is the second methoid.

.cpp

void Flasher::flasher (int times);//prefix Flasher: indicates methoid belongs to Flasher class

Do you see the difference between the declaration and the definition.

Also, the word is spelled "method", not "methoid".

Actually the correct term is "function". There is no such thing as a method in C++. The term "method" is commonly used though and anyone will know what you're talking about so not a big deal.

Once you get the compilation issues squared away, you can then begin working on the logic issues.

You should NOT be doing hardware-related things in the class constructor. Yes, I know that the example came straight from adafruit, but that does not mean that it is any good.

Thanks ill make the changes and get back. Is there a way to do hardware related things? that's 90% of what I will be doing.

turbonasty:
Thanks ill make the changes and get back. Is there a way to do hardware related things? that's 90% of what I will be doing.

Instead of in the constructor, use a begin() method for the pinMode.

const int ledPin = 13;
const int slowDuration =300;
const int fastDuration = 100;

capital constants. help locate them around your code.

const int LEDPIN = 13;
const int SLOWDURATION =300;
const int FASTDURATION = 100;

nitrof:
capital constants. help locate them around your code.

Also more work to type. I prefer to use caps only for macros, with underlines to split words. All my variables are camelCase. To each their own, the important thing it just to be consistent with whatever scheme you chose.

pert:
Also more work to type.

I have a caps lock key, not sure about you.

aarg:
I have a caps lock key, not sure about you.

I disabled mine, haven’t missed it a bit.

pert:
I disabled mine, haven't missed it a bit.

HOW DO YOU SHOUT AT PEOPLE THEN?

Thanks for the help. I looked over the example one more time. I missed some capital letters. I fixed them and added spaces. the semicolons were in the example so I didn't move them. It still didn't work. so I took out the comments. nope that didn't do it. finally I took out semicolons... that did it. once I took them out the code looked more like what I am getting use to seeing. I'll post the new code just for reference.

There were some words used that I don't know so I'm going to do some googling. If I still don't get it I'll ask here. That brings us another question I have. I took a screen shot on my phone of a post on another forum. Someone asked about shortening up his code, and the next guy did. It looks like two different codes. So would it be ok to post the pic here?

#include <Flasher.h>


const int ledPin = 13;
const int slowDuration =300;
const int fastDuration = 100;

Flasher slowFlasher (ledPin, slowDuration);
Flasher fastFlasher (ledPin, fastDuration);


void setup() {}

void loop() {
slowFlasher.flash (5);
delay (1000);
fastFlasher.flash(10);
delay(2000);
}

.h

//led flashing libarary

#include "Arduino.h"

class Flasher
{
public:
Flasher (int pin, int duration);
void flash (int times);
private:
int _pin;
int _d;
};

.cpp

#include "Flasher.h"

Flasher::Flasher (int pin, int duration){
	pinMode (pin, OUTPUT);
	_pin = pin;
	_d = duration / 2;
}
void Flasher::flash (int times){
	for (int i = 0; i < times; i++)
	{
		digitalWrite (_pin, HIGH);
		delay (_d);
		digitalWrite (_pin, LOW);
		delay (_d);
	}
}

sorry forgot code in last post!! Thanks for the help!!!

turbonasty:
I took a screen shot on my phone of a post on another forum. Someone asked about shortening up his code, and the next guy did. It looks like two different codes. So would it be ok to post the pic here?

It would be okay, but it would be much kinder to us, if you could copy and paste it as text. Else try to understand and describe it for us. Can you only access that forum on your phone?

It easier from my phone I am always on the move. I don't sit in front of a computer much. I have been lately for the purpose of learning code. It doesn't help I am using an iphone so no java. I will look for the post I took the pic of and copy the code.

turbonasty:
There were some words used that I don't know so I'm going to do some googling. If I still don't get it I'll ask here. That brings us another question I have. I took a screen shot on my phone of a post on another forum. Someone asked about shortening up his code, and the next guy did. It looks like two different codes. So would it be ok to post the pic here?

If it's unrelated to this topic, make a new thread.

I believe posting the link to the forum post would be more acceptable than a screenshot.