custom library testing error [solved]

I’ve been using Arduino for a good while now, so I’m pretty familiar with the basics, but I’ve just started getting into the details of libraries, specifically writing my own libraries. As a test library, I created a basic blink library using the format given in the Morse tutorial here;

https://www.arduino.cc/en/Hacking/LibraryTutorial

I created the cpp file first, and made it as simple as possible. Here it is;

/*
test library 1 cpp file
*/

#include “Arduino.h”
#include “test1.h”

test1::test1()
{
}

void test1::Blink() {
digitalWrite(13, 1);
delay(500);
digitalWrite(13, 0);
delay(500);
}

Then I made the h file;

/*
test library 1
*/
#ifndef test1_h
#define test1_h

#include “Arduino.h”

class test1
{
public:
test1();
void Blink();
private:
};

#endif

Finally I did the keyword file;

test1 KEYWORD1
Blink KEYWORD2

I can’t find anything wrong with any of it, but it’s probably something really simple and obvious. Anyway, I tried to use it with this code (after restarting the arduino environment of course);

#include <test1.h>

test1 test();

void setup() {
pinMode(13, OUTPUT);
}

void loop() {
test.Blink(13, 500, 10);
}

Unfortunately I keep getting this error;

test1library.ino: In function ‘void loop()’:
test1library:10: error: request for member ‘Blink’ in ‘test’, which is of non-class type ‘test1()’
request for member ‘Blink’ in ‘test’, which is of non-class type ‘test1()’

I’m not sure what this means and I certainly don’t know how to fix it. Any suggestions or ideas would be greatly appreciated.
~Josh

update: final code is in the last reply

test1 test();

Lose the parenthesis here.

test.Blink(13, 500, 10);

The next error will be that it can't find a version of Blink in your class that takes arguments. The one you defined takes no arguments.

Delta_G, Thank you for the response. I got rid of the parenthesis in test1 test(); It now reads test1 test in the void loop section. I got exactly the error you predicted. The exact wording was;

test1library.ino: In function 'void loop()': test1library:10: error: no matching function for call to 'test1::Blink(int, int, int)' test1library.ino:10:23: note: candidate is: In file included from test1library.ino:1:0: C:\Users\Isaac\Documents\Arduino\libraries\test1/test1.h:13:6: note: void test1::Blink() void Blink(); ^ C:\Users\Isaac\Documents\Arduino\libraries\test1/test1.h:13:6: note: candidate expects 0 arguments, 3 provided no matching function for call to 'test1::Blink(int, int, int)'

I don't quite understand what that means, however, and I'm not sure what you mean by "The one you defined takes no arguments." I'm familiar with the basics of arduino, but I have no background in c++ or any programming whatsoever. ~Josh P.S. I apologize for not using the code inserts, for some reason when I try to the code is butchered beyond legibility.

void test1::Blink() {
digitalWrite(13, 1);
delay(500);
digitalWrite(13, 0);
delay(500);
}

See the empty parenthesis? There are no arguments there for it to take. Where did you expect those numbers in the function call to go? You have to tell a function what to do with the arguments you give it.

I guess you want the 13 to be the pin number and the 500 to be the delay. But what did you want the 10 to do?

If you want to write a version that takes two arguments for the pin number and delay it might look like:

void test1::Blink(int aPin, int aDelay) {
digitalWrite(aPin, 1);
delay(aDelay);
digitalWrite(aPin, 0);
delay(aDelay);
}

Of course you need to add the declaration to your class in the .h as well.

class test1
{
public:
test1();
void Blink();
void Blink(int, int);
private:
};

Google "C++ Functions" for several good tutorials on writing functions in C++.

Delta_G,
Thank you tremendously for your help. I knew it would be something simple that I overlooked! You are correct, the 13 is the pin, the 500 is the delay, and the 10 is left over from a function I had when I originally wrote the library. I wrote it a bit more complicated, then when it didn’t work, I simplified it, apparently not very well. Again, thank you for the assistance!
If anyone is interested, here’s the final code;

h file:

/*
test library 1
*/
#ifndef test1_h
#define test1_h

#include “Arduino.h”

class test1
{
public:
test1();
void Blink();
void Blink(int, int);
private:
};

#endif

cpp file:

/*
test library 1 cpp file
*/

#include “Arduino.h”
#include “test1.h”

test1::test1()
{
}

void test1::Blink(int aPin, int aDelay) {
digitalWrite(aPin, 1);
delay(aDelay);
digitalWrite(aPin, 0);
delay(aDelay);
}

keywords file:

test1 KEYWORD1
Blink KEYWORD2

simple code:

#include <test1.h>

test1 test;

void setup() {
pinMode(13, OUTPUT);
}

void loop() {
test.Blink(13, 500);
}

~Josh

void test1::Blink(int aPin, int aDelay) {
digitalWrite(aPin, 1);
delay(aDelay);
digitalWrite(aPin, 0);
delay(aDelay);
}

You really don't need to use an integer for your pin number (unless you're using an Arduino with more than 255 I/O pins). So maybe it's better to do:

void test1::Blink(byte aPin, int aDelay) {
digitalWrite(aPin, 1);
delay(aDelay);
digitalWrite(aPin, 0);
delay(aDelay);
}

Just being a bit pedantic tonight.

Regards,

Brad

PS since I'm on a roll, you might want to check out proper include syntax as well.

EDIT: PPS: Since I was complaining about minor nits, why didn't I suggest using HIGH/LOW on your digitalWrite() calls? Guess I missed that.

Brad Burleson, Thanks for the suggestions! This was just a test library, so I'm done messing with it, but I'll keep your ideas for the future. As for the HIGH/LOW vs 1/0, it's just shorter and I'm lazy XD As far as I know, it doesn't make a difference, but it's entirely possible it'll cause problems later on.