Pages: [1]   Go Down
Author Topic: Problem adding library  (Read 596 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm having trouble adding libraries, it doesn't get recognized by the compiler when i add it like so:
IMG attached
Code: (sfdk.h)
#ifndef sfdk_h
#define sfdk_h
#include "Arduino.h"

#endif


* sfdk.jpg (6.4 KB, 189x103 - viewed 19 times.)
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 200
Posts: 12779
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
...doesn't get recognized...

Reading glasses.  Your compiler needs a pair.  Works for me every time.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
...doesn't get recognized...

Reading glasses.  Your compiler needs a pair.  Works for me every time.

How so?
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 200
Posts: 12779
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


The point is that "doesn't get recognized" tells us nothing about the actual problem.

Are you saying you are getting a compilation error?  That the program builds but clearly is not including the code you expect to be included?  That syntax highlighting is not working?  That the compiler is whining about its myopia?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The program doesn't include the libraries i created, i had tested it before on a DC motor i had to simplify some stuff, adding functions like motor.FWD(); but for some reason when i wanted to try again today it just doesn't do anything. It compiles with no errors

EDIT: sorry
Quote
rev1:11: error: 'Motor' does not name a type
rev1:12: error: 'Motor' does not name a type
rev1.ino: In function 'void loop()':
rev1:20: error: 'motorIzquierdo' was not declared in this scope
rev1:21: error: 'motorDerecho' was not declared in this scope

Code:
#include <motor.h>
Motor motorIzquierdo(0,1);
Motor motorDerecho(2,3);

void setup()
{
}

void loop()
{
  motorIzquierdo.Adelante();
  motorDerecho.Adelante();
  delay(3000);
  motorIzquierdo.Atras();
  motorDerecho.Atras();
  delay(3000);
  motorIzquierdo.Parar();
  motorDerecho.Parar();
  delay(3000);
}
« Last Edit: March 08, 2013, 08:35:30 pm by LaloHao » Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Link to the library?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Link to the library?

Code: (motor.h)
#ifndef motor_h
#define motor_h
#include "Arduino.h"

class Motor
{
  public:
    Motor(int pin1, int pin2);
void Adelante();
void Atras();
void Parar();
int Estado();
  private:
    int _pin1,_pin2,_flag;
};
#endif

Code: (motor.cpp)
#include "Arduino.h"
#include "Motor.h"

int _flag;

Motor::Motor(int _pin1, int _pin2)
{
pinMode(_pin1, OUTPUT);
pinMode(_pin2, OUTPUT);
Motor::Parar();
}

int Motor::Estado()
{
return _flag;
}

void Motor::Parar()
{
digitalWrite(_pin1, LOW);
digitalWrite(_pin2, LOW);
_flag = 0;
}

void Motor::Adelante()
{
  digitalWrite(_pin1, HIGH);
  digitalWrite(_pin2, LOW);
  _flag = 1;
}

void Motor::Atras()
{
  digitalWrite(_pin1, LOW);
  digitalWrite(_pin2, HIGH);
  _flag = 2;
}
Logged

Offline Offline
Faraday Member
**
Karma: 61
Posts: 2879
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

When you add a library,   you need to close and re-start the IDE.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It's also a really good idea to make the file names EXACTLY match the class name. The files should be Motor.cpp and Motor,h, not motor.cpp and motor.h.

Quote
When you add a library,   you need to close and re-start the IDE.
That depends on where you add the library. Add it to the libraries folder, and yes the IDE needs to be restarted. Add it to the sketch folder, using the create tab option, and no, it does not need to be restarted.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It's also a really good idea to make the file names EXACTLY match the class name. The files should be Motor.cpp and Motor,h, not motor.cpp and motor.h.
Typo, they are actually named Motor.cpp and Motor.h and in ~/Documents/Arduino/Libraries folder

Quote
When you add a library,   you need to close and re-start the IDE.
That depends on where you add the library. Add it to the libraries folder, and yes the IDE needs to be restarted. Add it to the sketch folder, using the create tab option, and no, it does not need to be restarted.
I did restart every time i tried to add it. And for some reason i followed your advise of adding it to the sketch and it turns out it says i'm declaring classes twice which means it actually added the library after i added the file to the sketch, i just deleted the sketch and it seems to work again. Wierd?
Well, at least it works now, thanks  everyone!
Logged

Pages: [1]   Go Up
Jump to: