I am connecting my Arduino to a Dobot in order to do certain actions in order. I am able to turn it on when digitalRead StartButton == HIGH, however I am unable to turn it off when digitalRead StartButton == LOW, instead the code runs for a while more before stopping. I believe it is because the serial inputs to the arduino is faster than the execution of commands by the Dobot, however I am unsure. This is what my serial monitor prints when digitalRead == HIGH. I am still new to Arduino and C++, I apologise if the question is dumb. I have put parts of the code down.
High
Tx Packet: Packet header:aa aa, id:84, ctrl:03, payloadLen:19
params: 02 00 80 89 43 00 00 00 00 00 00 20 42 00 00 00 00
checksum:f9
Tx Packet: Packet header:aa aa, id:84, ctrl:03, payloadLen:19
params: 02 00 00 00 00 00 00 7a 43 00 00 20 41 00 00 00 00
checksum:89
Tx Packet: Packet header:aa aa, id:84, ctrl:03, payloadLen:19
params: 02 00 00 00 00 00 00 7a 43 00 00 20 c1 00 00 00 00
checksum:09
Tx Packet: Packet header:aa aa, id:84, ctrl:03, payloadLen:19
params: 02 00 00 00 00 00 00 7a 43 00 00 20 42 00 00 00 00
checksum:88
Tx Packet: Packet header:aa aa, id:84, ctrl:03, payloadLen:19
params: 02 00 00 6b 43 00 00 00 00 00 00 f0 c1 00 00 00 00
checksum:48
High
Tx Packet: Packet header:aa aa, id:84, ctrl:03, payloadLen:19
params: 02 00 00 6b 43 00 00 00 00 00 00 20 42 00 00 00 00
checksum:97
Tx Packet: Packet header:aa aa, id:84, ctrl:03, payloadLen:19
params: 02 00 00 00 00 00 00 7a 43 00 00 20 41 00 00 00 00
checksum:89
Tx Packet: Packet header:aa aa, id:84, ctrl:03, payloadLen:19
params: 02 00 00 00 00 00 00 7a 43 00 00 20 c1 00 00 00 00
checksum:09
Tx Packet: Packet header:aa aa, id:84, ctrl:03, payloadLen:19
params: 02 00 00 00 00 00 00 7a 43 00 00 20 42 00 00 00 00
checksum:88
Tx Packet: Packet header:aa aa, id:84, ctrl:03, payloadLen:19
params: 02 00 00 7f 43 00 00 00 00 00 00 20 42 00 00 00 00
checksum:83
Tx Packet: Packet header:aa aa, id:84, ctrl:03, payloadLen:19
params: 02 00 00 7f 43 00 00 00 00 00 00 f0 c1 00 00 00 00
void loop()
{
ButtonStateStart = digitalRead(StartButton);
InitRAM();
ProtocolInit();
printf("\r\n======Enter demo application======\r\n");
for(; ;)
{
static uint32_t timer = millis();
static uint32_t count = 0;
#ifdef JOG_STICK
#else
if(millis() - timer > 2000)
{
timer = millis();
count++;
while (ButtonStateStart = digitalRead(StartButton) == HIGH)
{
move1();
Serial.println("High");
PutDown();
ButtonStateStart = digitalRead(StartButton);
if (ButtonStateStart == LOW)
break;
move2();
Serial.println("High");
PutDown();
ButtonStateStart = digitalRead(StartButton);
if (ButtonStateStart == LOW)
break;
move3();
Serial.println("High");
PutDown();
ButtonStateStart = digitalRead(StartButton);
if (ButtonStateStart == LOW)
break;
move4();
Serial.println("High");
PutDown();
ButtonStateStart = digitalRead(StartButton);
if (ButtonStateStart == LOW)
break;
}
}
#endif
}
}
void PutDown()
{
gPTPCmd.z = 40;
SetPTPCmd(&gPTPCmd, true, &gQueuedCmdIndex);
ProtocolProcess();
gPTPCmd.x = 0;
gPTPCmd.y = 250;
gPTPCmd.z = 10;
gPTPCmd.r = 0;
SetPTPCmd(&gPTPCmd, true, &gQueuedCmdIndex);
ProtocolProcess();
gPTPCmd.z = -10;
SetPTPCmd(&gPTPCmd, true, &gQueuedCmdIndex);
ProtocolProcess();
delay(1000);
StopSuck();
gPTPCmd.z = 40;
SetPTPCmd(&gPTPCmd, true, &gQueuedCmdIndex);
ProtocolProcess();
}
void move1()
{
gPTPCmd.x = 235;
gPTPCmd.y = 0;
gPTPCmd.z = 40;
gPTPCmd.r = 0;
SetPTPCmd(&gPTPCmd, true, &gQueuedCmdIndex);
ProtocolProcess();
gPTPCmd.z = -30;
SetPTPCmd(&gPTPCmd, true, &gQueuedCmdIndex);
ProtocolProcess();
Suck();
delay(1300);
}