I am trying and failing to covert a sketch into a library.
Using an Arduino Zero.
In sketch form:
Variable of type Uart is defined as follows:
Uart* serPort = &serial2;
There is a function that switches between &serial1
and &serial2
.
This works.
Now I am trying to implement the same into the library:
Defined in the main code as follows:
Sender Sender(Serial2);
Here is the header file:
class Sender
{
public:
Sender(Uart PortIn);
private:
Uart* serPort;
};
Here is the .cpp file:
Sender::Sender(Uart PortIn)
{
byte data[]={0xff,0xaa};
serPort = &PortIn;
serPort->write(data,2);
}
This complies but something must crash on startup as the USB port is lost. Reset button has to be pressed to start the bootloader.
I cannot seem to find what is wrong.
I think you need to send the argument as a reference or a pointer to the constructer.
In main, It should look something like:
Hope it helps.