Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: Problem adding library on: March 09, 2013, 08:30:55 am
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!
2  Using Arduino / Programming Questions / Re: Problem adding library on: March 08, 2013, 09:26:21 pm
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;
}
3  Using Arduino / Programming Questions / Re: Problem adding library on: March 08, 2013, 08:31:19 pm
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);
}
4  Using Arduino / Programming Questions / Re: Problem adding library on: March 08, 2013, 08:21:34 pm
Quote
...doesn't get recognized...

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

How so?
5  Using Arduino / Programming Questions / Problem adding library on: March 08, 2013, 08:09:56 pm
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
Pages: [1]