Hi,
I am trying to write my first Arduino library.
Everything was fine until I decided to try references.
In my class ‘MYCLASS’ I have a privat class variable _PCF where I want to keep a reference to some other class/object (PCF8574).
How I try to do it:
MYCLASS.h
#ifndef MYCLASS_h
#define MYCLASS_h
#include <Arduino.h>
#include <PCF8574.h>
class MYCLASS {
public:
MYCLASS();
void begin(PCF8574& PCF);
void test();
private:
PCF8574 _PCF;
};
#endif
MYCLASS.cpp
#include "MYCLASS.h"
#include <Arduino.h>
#include <PCF8574.h>
MYCLASS::MYCLASS();
void MYCLASS::begin(PCF8574& PCF) // referense using '&'
{
_PCF = PCF;
_PCF.pinMode(0,OUTPUT);
_PCF.pinMode(1,OUTPUT);
}
void MYCLASS::test()
{
_PCF.digitalWrite(0,HIGH);
}
This is how I want to use it:
PCF8574 a;
MYCLASS mc;
void setup() {
mc.begin(a);
a.begin(b1000000);
mc.test();
}
That does not work of course - I know… that would be to easy.
Could you please help me to solve this problem please!
Thanks!