Sketch and wire.h

I had my sketch and it worked, now I separate in my own Library and it stop working :disappointed_relieved:

What's wrong??? I'm forgetting somethin??

#include <Wire.h>
#include "Compas.h"

Compas com;

void setup()
{
    
}
/////////////////////////////////////////////

////////////////////////////////////
void loop() {

     com.Escribir();
}
#ifndef Compas_h
#define Compas_h

#include <Wire.h>
#include "WProgram.h"

class Compas {

  public:
    	Compas();

    	void Escribir();
  private:
        void Orientacion();

        int HMC6352Direccion;
        int HMC6352;
        int ContBrujula;
        int grados;
        byte entradagrados[2];
};

#endif
#include "Compas.h"

Compas::Compas()
{
    HMC6352 = HMC6352Direccion >> 1;
    Wire.begin();
}

void Compas::Orientacion()
{
    ContBrujula = 0;
    Wire.beginTransmission(HMC6352);
    Wire.send("A");
    Wire.endTransmission();
    delay(10);
    Wire.requestFrom(HMC6352,2);
    while(Wire.available() && ContBrujula < 2)
    {
    entradagrados[ContBrujula] = Wire.receive();
    ContBrujula++;
    }
    grados = int((entradagrados[0]*256)/10);
}

void Compas::Escribir()
{
    Orientacion();

    if(grados>=100){
        Serial.print(grados);
    }else if(grados>=10 && grados<100){
        Serial.print("0");
        Serial.print(grados);
    }else if(grados<10){
        Serial.print("00");
      	Serial.print(grados);
    }
}

hook24:
What's wrong???

Good question. What is wrong?
Does it build but not work? fail to build? fail to download?
If it fails to build, can you mention the errors that you get?

gardner:

hook24:
What's wrong???

Good question. What is wrong?
Does it build but not work? fail to build? fail to download?
If it fails to build, can you mention the errors that you get?

the sensor don't answer, don't work, it's like the pins aren't in activity

Does Wire.begin() work in a constructor?

Google: "c++ initialize static variables fiasco"

Specifically:

http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.14

Right. Basically the solution here is to take Wire.begin() out of the constructor. Arduino libraries use ".begin()" for most of their setup, so you could put your setup things into Compas::begin().

I think it's best of all to NOT call Wire.begin() anywhere in the library, but rather to expect the user to call it first. This is a bit of a defensive programming practice on my part. The reason is that what happens when I want to have TWO different libraries, Compas and my 24LC26 EEPROM, for example, that use I2C.

myCompas.begin()
myEeprom.begin();

In this case, myEeprom.begin() calls Wire.begin() AGAIN, and did that maybe break something that myCompas set up? Dunno. So I avoid it.

Thanks to everyone 8)