您需要将对象从两个字节的结构转换为两个字节的 int,通过端口在 ESP 到 arduino 之间传输,反之亦然,然后将其转换回结构。
C++ 语言,但没有库。
struct PIN
{
unsigned char PinAndComand;
unsigned char PWN;
};
PIN obj;
int content;
// content = (int)obj;
// obj = (PIN)content;
做什么的?在arduino中,没有办法通过序列传递结构,只有int。我需要为 arduino 的 esp 做一个端口倍增器。
为什么不使用 int 而不是 struct。
两年来,房间控制板只在esp上工作。但是我需要进行更改,但是我丢失了固件并且不记得锯了。我决定适当地制作一个新的,以免害怕触摸它。

我们采取
union:https://ideone.com/aUnlKy
您可以使用 reinterpret_cast 进行转换
或者像这样:
现在在 my_int 变量中,您有来自 PIN 结构的值。你可以在任何地方传递这个 int。