|
用按钮控制舵机,给舵机一个周期20毫秒,脉宽为1的脉冲,一共12个按钮,把脉冲函数放在第一个按钮成功过一次,放在最后一个按钮没成功过,怀疑是按钮过多,同步性不好,求大佬指教
前两个按钮代码:
void button1_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
if (state == BLINKER_CMD_BUTTON_TAP) {
BLINKER_LOG("Button tap!");
_stop();
}
else if (state == BLINKER_CMD_BUTTON_PRESSED) {
BLINKER_LOG("Button pressed!");
//forward();
for(int i=0;i<50;i++)
{
digitalWrite(xinhao1,HIGH);
Blinker.delay(3);
digitalWrite(xinhao1,LOW);
Blinker.delay(17);
}
}
else if (state == BLINKER_CMD_BUTTON_RELEASED) {
BLINKER_LOG("Button released!");
_stop();
}
else
{
BLINKER_LOG("Button released!");
_stop();
}
}
void button2_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
if (state == BLINKER_CMD_BUTTON_TAP) {
BLINKER_LOG("Button tap!");
_stop();
}
else if (state == BLINKER_CMD_BUTTON_PRESSED) {
BLINKER_LOG("Button pressed!");
backward();
}
else if (state == BLINKER_CMD_BUTTON_RELEASED) {
BLINKER_LOG("Button released!");
_stop();
}
else
{
BLINKER_LOG("Button released!");
_stop();
}
}
|
|