Error: expected constructor, destructor, or type conversion before '=' toke

Error: expected constructor, destructor, or type conversion before '=' toke

不太清楚为什么我会在这里收到错误消息。使用 Arduino 及其编译器。如果有人能帮我解决这个问题,我将不胜感激。

unsigned char topState, leftState, rightState, fwdState, bwdState;
topState = leftState = rightState = fwdState = bwdState = 1;

Error: expected constructor, destructor, or type conversion before '=' token

您不能在 function/method 上下文之外使用赋值语句。正确初始化:

unsigned char topState = 1, leftState = 1, rightState = 1, fwdState = 1, bwdState = 1;

或者write/call某处的初始化函数。