该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
for (uint8_t b=0; b<2; b++) {
if (buttons[b].contains(p.x, p.y)) {
buttons[b].press(true); // tell the button it is pressed 告诉按钮它被按下了
}
else {
buttons[b].press(false); // tell the button it is NOT pressed 告诉按钮没有按
}
}
// now we can ask the buttons if their state has changed 现在我们可以询问按钮的状态是否发生了变化
for (uint8_t b=0; b<2; b++) { //for (uint8_t b=0; b<15; b++) {//实际值为4
if (buttons[b].justReleased()) { //获释
buttons[b].drawButton(); // draw normal正常
status(F(" "));
pu = 0;
a = 2;
}
if (buttons[b].justPressed()) { //按下
buttons[b].drawButton(true); // draw invert!画反 // its always OK to just hang up 挂断总是可以的
if (b == 0) {
if ( position < 287500) {
status(F("Moving..."));
digitalWrite(DIR,LOW);//high(右) 11 前进 控制方向
pu = 100;
while(b == 0) {
digitalWrite(PUL,HIGH);
delayMicroseconds(pu);
digitalWrite(PUL,LOW);
delayMicroseconds(pu);
i++;
if(i > 20) {
s = position * y; //运动距离
tft.fillRect(15, 15, 210, 50, ILI9341_BLACK); //clear result box
tft.setCursor(30, 30);
tft.setTextSize(3);
tft.println(s); //update new value更新新值
i = 0;
}
}
}
}
if (b == 1) {
if ( position > 0) {
status(F("Backing..."));
digitalWrite(DIR,HIGH);// LOW(左) 11 后退 控制方向
pu = 100;
while( b == 1 ) {
digitalWrite(PUL,HIGH);
delayMicroseconds(pu);
digitalWrite(PUL,LOW);
delayMicroseconds(pu);
i++;
if(i > 20) {
s = position * y; //运动距离
tft.fillRect(15, 15, 210, 50, ILI9341_BLACK); //clear result box
tft.setCursor(30, 30);
tft.setTextSize(3);
tft.println(s); //update new value更新新值
i = 0;
}
}
}
}
}
}
以上是我的代码,如何在我松开之后停止运动呢,现在的情况是按下前进也就是b = 0是,就一直在循环运动,送掉按键也没用,按其他的按键也不可以,求助啊,拜托