library

okay, so i am trying to write a library that will also use the Wire library. when i do #include <Wire.h> in the c++ and header files it doesnt know what Wire is. is. how would i go about doing this?

For one thing, I think it should only be in the .h file. Please copy and post the exact error message.

error

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.
Arduino: 1.0.6 (Windows NT (unknown)), Board: "Arduino Mega 2560 or Mega ADK"
Master.cpp:2:18: error: Wire.h: No such file or directory
Master.cpp:8:14: error: empty character constant
Master.cpp: In member function 'void Master::init()':
Master.cpp:23: error: 'Wire' was not declared in this scope
Master.cpp:26: error: expected `;' before 'COP'
Master.cpp: At global scope:
Master.cpp:37: error: prototype for 'void Master::requestEvent()' does not match any in class 'Master'
Master.h:13: error: candidate is: void Master::requestEvent(int)
Master.cpp:50: error: prototype for 'void Master::recieveEvent(int)' does not match any in class 'Master'
Master.h:17: error: candidate is: void Master::recieveEvent()
Master.cpp: In member function 'void Master::request(byte)':
Master.cpp:86: error: 'Wire' was not declared in this scope
Master.cpp:94: error: 'Wire' was not declared in this scope
Master.cpp:94: error: expected `)' before numeric constant

Master.cpp

#include "Arduino.h"
#include "Wire.h"
#include "Master.h"

Master::Master(byte addr)
{
	Serial.begin(9600);
	if (addr != '')
	{
		ADDR = addr;
		Serial.print("addr set to ");
		Serial.println(ADDR);
	}
	else {
		Serial.println("addr will be set to 0");
		ADDR = 0;
	}
	
}

void Master::init()
{
	Wire.begin(ADDR);
	Wire.onRequest(requestEvent);
	Wire.onRecieve(recieveEvent)
	COP = 0;
	Pt1 = false;

}

void Master::setOP(byte op)
{
	COP = op;
	Pt1 = false;
}

void Master::requestEvent()
{
	if (Pt1 != true)
	{
		Wire.write(COP);
	}
	else
	{
		Wire.write(Writethis);
	}

}

void Master::recieveEvent(int howMany)
{
	if(Pt1)
	{
		Recieve = "";
		while (0 < Wire.available())
		{
			char c = Wire.read();
			Serial.println(c);
			Serial.println(Recieve);
			Recieve += c;
		}
		Pt1 = false;
		Serial.println(Recieve);
	}
	else
	{
		Serial.println("receiving unknown signal");
		Recieve = "";
		while (0 < Wire.available())
		{
			char c = Wire.read();
			Serial.println(c);
			Serial.println(Recieve);
			Recieve += c;
		}
		Pt1 = false;
		Serial.println(Recieve);

	}
}

void  Master::request(byte addr)
{
	if (Pt1 != true)
	{
		Wire.requestFrom(addr, 1);
		SCOP = Wire.read();
		Pt1 = true;
	}
	else
	{
		if (SCOP == 1)
		{
			Wire.requestFrom(addr 1);
			Serial.println(Wire.read());
			Pt1 = false;
		}
		else
		{
			Pt1 = false;
		}
	
	}		
}

master.h

#ifndef Master_h
#define Master_h

#include "Arduino.h"
#include "Wire.h"

class Master
{
	public:
		
		Master(byte addr);
		void requestEvent(int howMany);
		void init();
		void setOP(byte op);
		void request(byte addr);
		void recieveEvent();

	private:

		byte ADDR;
		byte COP;
		boolean Pt1;
		String Recieve;
		String Writethis;
		char SCOP;

};

#endif

ino file

#include "Master.h"

Where is your Wire library located? Did you try:

#include <Wire.h>

?

This isn’t the same as what you claimed that you used. It’s in quotes, not <>.

#include "Wire.h"

Also I told you it’s not supposed to be in the .cpp file, you have taken no action.

Arduino: 1.0.6 (Windows NT (unknown)), Board: "Arduino Mega 2560 or Mega ADK"

IDE 1.0.6 is VERY old. I would highly recommend that you update to a current version of the IDE.
One big change is that the newer IDEs better handle locating Arduino libraries.
The older IDEs had many issues & bugs in this area that have been fixed.
Older IDEs also did not search inside a library for library dependencies.
The newer IDEs are smart enough to locate libraries that a library may use/need that a sketch does not.

You really need to use a newer IDE, even if just for the IDE library manager.

--- bill

It will be interesting to see whether Arduino IDE 1.8.5 works on Windows NT. Let us know how that goes alexm622.

im on windows 10...

Well the Arduino IDE thinks you’re using Windows NT:

alexm622:

Arduino: 1.0.6 (Windows NT (unknown)), Board: "Arduino Mega 2560 or Mega ADK"

but that may be only due to using an antiquated IDE version.

Especially if you are writing a library... don't you want to at least test it with the latest IDE?