Hi, I am trying to create a library that controls the LED on the arduino. I understand (quite well anyway) how libraries work, but I keep getting these error messages:
(I have shortened these to fit in the post max size)
error: return type specification for constructor invalid
error: two or more data types in declaration of 'size_t'
error: 'size_t' has not been declared (in numerous files)
error: 'size_t' has not been declared (in numerous files)
error: 'size_t' does not name a type (in numerous files)
error: declaration of 'operator new' as non-function
error: declaration of 'operator new []' as non-function
error: no members matching 'Print::write' in 'class Print'
What is wrong?!?!
Here is my library code:
LED.h
/*
A simpler way to interface with LEDs.
First created 2013
*/
class LED
{
public:
void LED();
void on();
void off();
void flash(int nooftimes, int waitbetweenchange);
}
class Board
{
public:
void Board();
void on();
void off();
void flash(int howmanytimes,int delaybetweenchange);
}
LED.cpp
#ifndef LED_h
#define LED_h
#include "LED.h"
#include "Arduino.h"
LED::LED(int pin)
{
pinMode(pin,OUTPUT);
}
Board::Board()
{
}
Board::on()
{
pinMode(13,OUTPUT);
digitalWrite(13,HIGH);
}
Board::off()
{
pinMode(13,OUTPUT);
digitalWrite(13,LOW);
}
Board::flash(int times, int wait)
{
pinMode(13,OUTPUT);
for(int i=0;i<=times;i++)
{
digitalWrite(13,HIGH);
delay(wait);
digitalWrite(13,LOW);
delay(wait);
}
}
#endif
Update:
I've changed some of the data types for the cpp file, now I get an error: no matching function for call to 'LED::LED(int);'
2nd Update:
I have added 2 semicolons after the classes in the .h and .cpp files, now this error pops up:
error: no matching function for call to 'LED::LED(int);' (as before)
But also:
LED/LED.h:10: note: candidates are: LED::LED()
LED/LED.h:8: note: LED::LED(const LED&)
So, there's a change at least!
Update:
YES YES YES AND LOADS MORE YESSES!!!!!!!!!
IT'S WORKING, HIP HIP HOORAY!!!!!!!!!
Sorry about that, I was sounding like an over-exited kid but hey, I AM an over-exited kid, and I've made my first library that works. Surely that's something to be pleased about?
The problems were:
My constructors (LED::LED() and Board::Board()) were voids. (should not have a data type)
There wasn't a semicolon after the classes.
The integer 'pin' was specific to LED::LED() so LED::on() etc. could not use it.
And that's it! That's all that has been causing we all this trouble! So now, armed with this new-found knowledge, I will bravely proceed once more into the land of code...
And thanks to Delta_G who gave me the right nudge in the right direction!